Summer Sale! All accounts are 50% off this week.

vandan's avatar
Level 13

Session destroy after redirect other route?

my question is when my session is destroy then redirect not in login i want to redirect another route so how to set route and where is set the route in which file or controller please guys help me i dont know how to set

0 likes
5 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Just update the redirectTo method in App\Http\Middleware\Authenticate

Haroon1296's avatar

in Middlware/Authenticate

protected function redirectTo($request)
{
    if (! $request->expectsJson()) {
        return route('login');
    }
}

replace into ....

protected function redirectTo($request) { if (! $request->expectsJson()) { return route(' Youre route here '); } }

and in route.php

Route::get('/','HomeController@index');

Route::group(['middleware' => ['auth']], function(){ // routes here... });

You can make another Middlware and just put it...

1 like
vandan's avatar
Level 13

@sinnbeck sir can you please guide me am i right or wrong

protected function unauthenticated($request, AuthenticationException $exception)
	{

    	return ($request->expectsJson() || $request->isJson())
            	    ? response()->json(['message' => $exception->getMessage()], 401)
                	: redirect()->guest(route('inactivity'))->withErrors([
                	'failed' => "Please login to access this page"]);
	}

i just replace the route in expection/handler file so is thiis correct or not?

Sinnbeck's avatar

Removed that overengineered answer and added a proper one above :)

1 like

Please or to participate in this conversation.