What function and how to use Controllers in Laravel

Asked

Viewed 404 times

1

I’m learning Laravel by a channel, and left me doubt... How should I create my Controllers? As far as I understand it, the view asks for it, the controller will validate and successfully calls the model.

But my general question is... How should I structure my controllers? For example:

Views are what the user sees, so it is easy to distinguish that they will be pages.

Models are database structures (tables)

And Controllers enters as what classification? I need a Controller for every page I have? My only information I have that they use functions.

I do not know if it was clear enough to understand the question, anything I change, but the summary would be...

How to structure a Controller in the Laravel?

PS: Making it clear, I’m new to programming and I really liked the framework Laravel, for the things he does along with PHP Artisan

1 answer

2


So I guess you haven’t looked at the documentation but all right, I’ll try to help.

Controller as the name suggests is the Controller class, which involves your logic and maybe your business rule, after all you should not leave this in the route files, you need the Controller to control a certain information for your view.

You can use a Controller for several more pages depending on you.

Law information relating to MVC to understand more. Also read about the SOLID .You must have read a little about Project Architecture, and if you have more questions you can also take a look at the Laravel documentation. There is more information about Controller ,examples and more usability of Controller Laravel Documentation about the Controller

I also advise you to see what design architecture is MVC. What is MVC?

  • 1

    Thanks! I just saw a video about SOLID from an MVC man and helped me a lot to understand how I should use and etc... I just didn’t quite understand the D part... I was very confused at the time.

  • DIP: would be the inversion principle , talks about decoupling. I found a link that has illustrations can help understand. http://ramonsilva.net/boas-praticas/solid/inversao-dependencies/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.