Laravel 5.4 - choose route based on role -
i have following code:
route::group(['middleware' => ['auth']], function () { dd($user); route::get('/', 'sitecontroller@index'); });
the $user created in appserviceprovider, not accessible in route:
public function boot() { view()->composer('layouts.main', function($view){ $employees = \app\bamboo::getemployees(); $employeeindex = \app\bamboo::getemployeeindex(auth()->user()->email, $employees); $view->with('employees', $employees); $view->with('user', $employees['employees'][$employeeindex]); }); }
is there why me choose function called in sitecontroller based on role (this contained in $user)?
i want this:
$method = $user->role === 'dev' ? 'index' : 'admin'; route::get('/', "sitecontroller@{$method}");
is possible?
you try
if($user->role === 'dev) route::get('/', "sitecontroller@index"); else route::get('/', "sitecontroller@admin");
another easy way if define function in site controller checks $user , returns route :
public function getroute(request $r){ if(auth::user()->role === 'dev') return $this->index($r); else return $this->admin($r); }
wiki
Comments
Post a Comment