Creating menus in Laravel
Menus are a common facet of most websites. In this recipe, we'll create menus using Laravel's nested views and change the default "state" of the menu item, depending on which page we're on.
Getting ready
For this menu, we need a standard installation of Laravel.
How to do it...
We need to follow these steps to complete the recipe:
In the
routes.php
file, create three routes as follows:Route::get('menu-one', function() { return View::make('menu-layout') ->nest('menu', 'menu-menu') ->nest('content', 'menu-one'); }); Route::get('menu-two', function() { return View::make('menu-layout') ->nest('menu', 'menu-menu') ->nest('content', 'menu-two'); }); Route::get('menu-three', function() { return View::make('menu-layout') ->nest('menu', 'menu-menu') ->nest('content', 'menu-three'); });
In the views directory, create a file named menu-layout.php and add the following code to it:
<!doctype html> <html lang="en"...