Well, I watched all of them earlier. I am new to MVC and Laravel. I will watch them again. So basically, this is what I understand.
All model and database queries must be done in the controller. And then pass the variables to the view from the controller.
Watch this http://vimeo.com/12643301
and read some of this guy's answers on SO: http://stackoverflow.com/questions/16356420/mvc-for-advanced-php-developers/16356866#answer-16356866
To be precise, what you are referring to is a template, not view. And yes, it is a bad practice, don't do that :)
Theres a lot of "watch this video" type responses here =)
I'm pretty new to Laravel but I have pretty extensive experience with codeigniter and a fairly thorough understanding of the MVC and these are my thought:
Though possible it isn't a good idea to call a model or directly query from the view. A core benefit of the MVC architecture is the ability to separate your data, logic and view/template from one another. Doing this allows your models, views, and controller to focus on doing one thing (ie: query the DB, get the data from the DB and apply some logic on it, build a template your users will see, etc...) and usually that one thing that is done is done well.
Another benefit of having that one thing do that one job is code maintainability. Weeks/months down the line when you're back editing this code again (because you will, we all do) you won't be scratching your head asking yourself why you put a database query into your view.
In the video I linked Uncle Bob talks>zakiaziz said:
Another benefit of having that one thing do that one job is code maintainability. Weeks/months down the line when you're back editing this code again (because you will, we all do) you won't be scratching your head asking yourself why you put a database query into your view.
This is what Uncle Bob presents in that video I linked, and this is why it was linked in the first place.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community