Search code examples
laravellaravel-5laravel-5.3laravel-5.5

How to show menu on the all pages Laravel?


I have the main template home.blade.php that contains section inside which is put another content files.

In this file I have left sidebar menu.

Also I have custom class Menu to displaying menu items.

Whete to call this custom class/service that menu will be showed on the all pages in project?

I dont want to create instance of class Menu in each controller classes.


Solution

  • What you want is Laravel’s View::share() method. You can instantiate the class in your AppServiceProvider class and make the variable available to all your views https://laravel.com/docs/5.5/views#sharing-data-with-all-views