Skip to content

Instantly share code, notes, and snippets.

@LivesInSpb
Last active September 12, 2018 09:17
Show Gist options
  • Save LivesInSpb/ea0386caa9fa31e422834ab463c25fe0 to your computer and use it in GitHub Desktop.
Save LivesInSpb/ea0386caa9fa31e422834ab463c25fe0 to your computer and use it in GitHub Desktop.
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
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment