Answer the question
In order to leave comments, you need to log in
How to make life easier when working with MVC?
Hello people (robots, ufo)!
I'll go straight to the question. There is a News model and a NewsController controller. The controller has CRUD methods (create, show, edit, destroy) and some others. There is a master template from which other templates are inherited and certain data from the controller is displayed there. This master template has a sidebar that displays sections of the News category - All news, industry news, other news. So, every time I have to write requests to get these sections in the controller methods - $news_category = NewsCategory::all() and stuff them into CRUD templates. How to get rid of this routine?
Answer the question
In order to leave comments, you need to log in
Use View::share()
in a class constructor to access a variable from any template.
You can use laravel.com/docs/4.2/responses#view-composers
You can use filters.
You can extend the base controller and pull the desired method.
And other options....
Before rendering the template, pass global variables to it.
https://gist.github.com/S-anasol/fd287d8b4d2255f998c7
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question