In AuthController make a function and make a redirectPath function which will replace redirectPath function which in RedirectsUsers traits
//following custom function assign for redirection page according role
public function redirect_to_desired_page_according_role(){
$user = Auth::user();
if ($user->isAdmin()) {
return '/master';
} elseif ($user->isTrainer()) {
return '/public_trainings';
} elseif ($user->isTrainee()) {
return '/bardtrainer';
} elseif ($user->isMonitor()) {
return '/clients';
}
}
//following function will replace the function which is in RedirectsUsers traits
public function redirectPath()
{
if (property_exists($this, 'redirectPath')) {
return $this->redirectPath;
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : $this->redirect_to_desired_page_according_role();
}
In RedirectIfAuthenticated.php change the handle function like following
public function handle($request, Closure $next)//following custom function assign for redirection page according role
public function redirect_to_desired_page_according_role(){
$user = Auth::user();
if ($user->isAdmin()) {
return '/master';
} elseif ($user->isTrainer()) {
return '/public_trainings';
} elseif ($user->isTrainee()) {
return '/bardtrainer';
} elseif ($user->isMonitor()) {
return '/clients';
}
}
//following function will replace the function which is in RedirectsUsers traits
public function redirectPath()
{
if (property_exists($this, 'redirectPath')) {
return $this->redirectPath;
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : $this->redirect_to_desired_page_according_role();
}
In RedirectIfAuthenticated.php change the handle function like following
{
if ($this->auth->check()) {
return redirect((new AuthController())->redirect_to_desired_page_according_role());
}
return $next($request);
}