LivesInSpb
9/12/2018 - 9:09 AM

Laravel -> AppServiceProvider -> boot()

Laravel -> AppServiceProvider -> boot()

Laravel have more interesting providers. For what? 
For example.

For all pages we have one block which get to us archives (months & year).
Ok.
We have Post model and method archives() which return list "Month Year"
Febriary 2018
January 2018
March 2017
etc.

This is simple for understands, I hope.

For sidebar we have one "view". This is very,very good choice.

So, let's see which "Provider" need to us?! 
AppServiceProvider. 
This class have 2 methos boot() & register().
We need "boot".
In this method we write code 
\View::composer() or 

view()->composer('layoyts.sidebar');

view()->composer('layoyts.sidebar', function($view){
	// code
});

view()->composer('layoyts.sidebar', function($view){
	$view->with('archives', \App\Post::archives());
	this means we get all records "archives" and insert into variable "archives", all the time if we find "layoyts.sidebar"  includes on the page
});