php - Prevent logout auth laravel
107
is there any way to listen the logout event and take decisions like redirect on auth laravel? I know there are some login/logout listeners but redirects are not working:
class LogSuccessfulLogout
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param Logout $event
* @return void
*/
public function handle(Logout $event)
{
if($event->user) {
$new = Auth::user()->cars()->where('status', 1)->count();
$inProgress = Auth::user()->cars()->where('status', 2)->count();
if($new > 0 || $inProgress > 0){
redirect('/');
}
}
}
}
Answer
Solution:
This is the default logout function called in in the default Laravel 5.2 AuthController
You can therefore set the
redirectAfterLogout
property to change the redirect url with the following code in your AuthController,or you can choose to simply override the logout function. Redirects will not work directly from your Listener.
Here's the modified logout function with your logic which you can place in your AuthController,