Deekshith
9 months ago

How to write custom redirect path after logout in Default Auth logincontroller.php

Posted 9 months ago by Deekshith

Hi Guys, I have developed role-based login mechanism using laravel Auth. Created 3 middleware namely, Admin, Vendor and Customer and written custom redirect rule in LoginController.php file like below,

protected function redirectTo( ) {

if (Auth::check() && Auth::user()->role == 3) {
    return '/customerhome';
}
elseif (Auth::check() && Auth::user()->role == 2) {
    return '/vendorhome';
}
else {
    return '/home';
}

}

Now i can achieve a custom redirect path for every role using above code. But I want to write a custom redirect path for every user after logout. Example: Admin should be redirected to /login after logout Vendor should be redirected to /vendorlogin after logout

i am using below function in LoginController.php

public function logout(Request $request) {

$this->performLogout($request);
return redirect()->route('your_route');
}

But I am not getting how to match role_id just like in redirectTo function to write custom redirect path login.. Please help me out with this guys.

Please sign in or create an account to participate in this conversation.