user3573738
user3573738

Reputation:

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.

Upvotes: 2

Views: 2973

Answers (2)

iLaxo Mit
iLaxo Mit

Reputation: 87

create a seperate file menu.blade.php and write menu code in this file, include menu.blade.php in other files like this. use this to extend code

@extends('menu')

Upvotes: 2

Rob Fonseca
Rob Fonseca

Reputation: 3849

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

Upvotes: 4

Related Questions