With Entrust, I implemented how user will be redirected to his own dashboard after login by adding this method in Authcontroller.php
protected function authenticated()
{
if(\Auth::user()->hasRole(['super_admin',]) ) {
return redirect('/dashboard');
} else if(\Auth::user()->hasRole(['staff_admin']) ) {
return redirect('/staff/dashboard');
} else if(\Auth::user()->hasRole(['subadmin_admin']) ) {
return redirect('/subadmin/dashboard');
}
}
What challenge I am facing right now is, for eg. if staff had logged in and redirected to his dashboard as
domain.com/staff/dashboard
but if he manually deletes the staff from url and tries to access Super-Admin Dashboard then Entrust throws 403 Error, but I want to redirect him to his dashboard, with message that " You are not authorized".
I tried to implement same code in RedirectIfAuthenticated middleware, but it gave error as hasRole called on Null.