I would like to make the menu dinamically, so instead showing "FILMS OF THE MONTH" it shows "FILMS OF DECEMBER" (see the image); being December the current month that update itself each month
My problem is that the menu does not belongs to an specific route/controller, therefore I can not pass the variable like I do with other routes. Example:
$month = Carbon::now()->format('F');
return view('partials._nav')
->withMonth($month);
I could "solve" that problem passing the month to ALL controllers/routes, but I am repeating many times the same code.
My questions are
1- Is there any way in Laravel to pass a variable to a kind of rootstate (like in Angular) so, I keep the variable available in All routes of my application?
2- Is there any way that I could return a variable to more than one view? So I just pass the variable to all views possible like:
return view('films.all', 'films.show', 'films.index', 'actors.show', 'actors.index')
->withMonth($month);
Any idea would be appreciated
Finally I have the solution:
public function boot()
{
View::composer('*', function ($view) {
$month = Carbon::now()->format('F');
$view->withMonth($month);
});
}

