Skip to content

Instantly share code, notes, and snippets.

@kauhat
Created September 11, 2017 12:05
Show Gist options
  • Save kauhat/bfd3e72f661b61d20e5a566f98073079 to your computer and use it in GitHub Desktop.
Save kauhat/bfd3e72f661b61d20e5a566f98073079 to your computer and use it in GitHub Desktop.
<?php
Menu::make(
'MainMenu',
function ($menu) {
$menu->add('Home', ['route' => 'home']);
$menu->add('About', ['route' => 'about']);
$menu->add('Contact', ['route' => 'contact']);
}
);
Menu::make(
'FooterMenu',
function ($menu) {
$menu->add('Terms & Conditions', ['route' => 'about.terms']);
$menu->add('Privacy & Cookies', ['route' => 'about.privacy']);
}
);
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
class MenuServiceProvider extends ServiceProvider
{
/**
* Define the menus for the application
*
* @return void
*/
public function boot()
{
View::composer('layouts.app', function () {
require_once base_path('menus/main.php');
require_once base_path('menus/user.php');
});
}
}
<?php
Menu::make(
'UserMenu',
function ($menu) {
if (Auth::guest()) {
$menu->add('Login', ['route' => 'login']);
$menu->add('Register', ['route' => 'register']);
} else {
if (Auth::user()->hasRole('admin')) {
$menu->add('Admin', ['route' => 'admin.home']);
$menu->divide();
}
$menu->add('Dashboard', ['route' => 'user.home']);
$menu->add('Logout')
->link
->attr('id', 'logout')
->href('#');
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment