Greetings, I just began to study Laravel, when a reasonable question arose on the assumption that it is extremely undesirable to keep business logic in controllers.

A simple script:

a person enters a domain in the form, if the regex data matched (I have the pattern) (I think regex should be checked in the controller), if the domain does not exist (this check must be done not in the controller as far as I understand it?) then

  • create a record in the database
  • redirect the user to the created domain ID

otherwise

  • redirect the user to the domain ID

How to organize it in a controller and why it should be implemented. I really hope for a detailed answer, thanks.

    1 answer 1

    To verify the entered domain, you can create a separate validation rule, it is better to validate in the controller. Redirects should also be made from the controller, and to create a record in the database you can make a method in the model and call it in the controller.