xxxxxxxxxx
views/
navigation/
admin.blade.php
guest.blade.php
xxxxxxxxxx
@if($userMenu)
<div class="navbar-main">
@include($userMenu)
</div>
@endif
xxxxxxxxxx
@if(Auth::user()->isAdmin())
@include('navigation.admin');
@endIf
@if(Auth::user()->isStudent())
@include('navigation.student');
@endIf
@if(Auth::user()->isTeacher())
@include('navigation.teacher');
@endIf
@if(Auth::user()->guest())
@include('navigation.guest');
@endIf
xxxxxxxxxx
<nav>
// all the shared stuff here
@if ( Auth::user()->isAdmin )
// some admin stuff
@endif
// shared stuff
@if ( Auth::user()->isAdmin )
// some more admin stuff
@endif
// you get the idea
xxxxxxxxxx
class NavigationComposer {
public function compose($view)
{
// Is a user logged in?
if(Auth::check())
{
// Grab the role name from the current session variable
// NOTE: you probably have a different way of doing this via a relation or similar
$currentRole = Session::get('user.current_role');
// try to get a navigation menu matching this user type
$user = Auth::user();
$viewName = 'navigation.' . strtolower($currentRole);
// If there is no view matching this, default to empty and show nothing
// you may want to set another default here
if( ! View::exists($viewName))
$viewName = '';
// Pass the user and user-specific view name to the navigation
$view->with([
'user' => $user,
'userType' => $currentRole,
'userMenu' => $viewName
]);
}
}
}