G
G
GrimJack2017-03-15 20:26:24
API
GrimJack, 2017-03-15 20:26:24

What is the correct way to write "API" for contact forms?

Laravel 5.4
In general, I am writing my bicycle rocket purely for myself, for learning Laravel. It is very sad that Google gives out information for version 5.3 at best.
The essence of the task: there are various forms on the site (let there be 2 of them), I want to send them to the server with Ajax (as I understand it, this requires a route in api.php, not web.php) and check (as I understand it for this middleware is needed) respond with an error or confirmation. When passing the "verification", the data will be - go to the PM by mail / post, write to the database and somewhere else (there are no problems with all this).
Substantive questions:

  1. I want to pass data through the "/ajax/contact/$formtype" route, then the contact controller with the corresponding $fomtype method ([email protected]$fomtype) will be called. Is this correct or how would it be correct? (e.g. there are 3 different forms with the same fields, this equals one $formtype )
  2. How to correctly validate data in forms through middleware? I didn’t understand anything from Google, maybe there is a sensible explanation like how to check files / phone / mail / etc.
  3. What can be the nuances or how would it be better / more correct to organize this? Maybe there are guides for version 5.4, because. cardinal difference from 5.3 and below

I ask you not to throw slippers, I'm just learning, and the Russian-speaking community is so-so.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question