TheBAST
TheBAST

Reputation: 2736

Laravel Session Destroy implementation

Another newb queestion here

How to apply session timeout in laravel? My app have this instance that when a user logs out. That previous route/s should not be loaded but my app loads it. how to implement in laravel that session destroy in PHP? Any ideas?

Upvotes: 1

Views: 683

Answers (1)

EddyTheDove
EddyTheDove

Reputation: 13259

In routes/web.php add your protected routes in a middleware group so they won't be accessible when logged out.

Route::group(['middleware' => 'auth'], function() {
    Route::get('profile', 'UserController@profile');
});

Then /profile will require users to be logged in. As well as any other routes in that group.

Learn more about sessions here: https://laravel.com/docs/5.4/session

Update

I think I've got what you mean. After doing Auth::logout(); do

return redirect()->back();

What will happen is the browser will try to redirect back to a 'protected' page and the protected page will kick them to the login page. WHen they click on 'back' on the browser, it will still display the login page.

Upvotes: 1

Related Questions