For variables used in layout, if parameters are passed from the controller, the operation needs to be repeated for each view!
How to solve the problem of passing the result to the layout after an operation for all views to use (I don’t want business code to appear in the layout view).
eg:
1. Permission management, set different menus according to different users!
2. Dynamic numbers in the menu, such as [Today’s Order (50)], that 50 requires all controllers to obtain the data and then pass it to the view!
There are two ways to solve it:
First: Traditional
ViewComposerProvider
Second, Laravel 5.1 new features @inject:
For example, you can do this:
Just query the data in SiteNav.
Digression: Read the documentation carefully and you can solve 80% of the problems you encounter.
Happy Hacking
The methods mentioned above are not reliable, and you cannot get the current url parameters and pass them into your function