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
]);
}
}
}