can sumone please help me with redirecting based on roles
i have two roles (admin,user) i want to redirect User to USER_HOME and admin to ADMIN_HOME ,and of course i have role column in the users table pleease help
You're using Entrust? If not, I strongly recommend this package to your projects. You can install via composer.
Link: https://github.com/Zizaco/entrust
With Entrust installed, you can try this:
public function index()
{
if(Entrust::hasRole('admin'):
return redirect('admin/home');
elseif(Entrust::hasRole('user'):
return redirect('user/home');
else:
// Do another thing.
endif;
}
public function home()
{
if ( auth()->user()->role == 'admin' ) {
return view('admin_view');
} else if ( auth()->user()->role == 'user' ) {
return view('user_view');
} else {
return "you don't have a role!"; // just an example
}
}