Laravel logout fail on pressing back button

前端 未结 5 1991
孤独总比滥情好
孤独总比滥情好 2021-01-06 18:17

On logout from my Laravel application using the Laravel logout method:

public function getLogout() 
    {
       Auth::logout();
       return Redirect::to(\         


        
5条回答
  •  半阙折子戏
    2021-01-06 19:05

    Since I am new in Laravel. So in Laravel 5.7 I fixed that problem in my way. Create a middleware using artisan.

    php artisan make:middleware RevalidateBackHistory
    

    Within RevalidateBackHistory middleware, we set the header to no-cache and revalidate.

    header('Cache-Control','nocache, no-store, max-age=0, must-revalidate')
                ->header('Pragma','no-cache')
                ->header('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
        }
    }
    

    Update the application’s route middleware in Kernel.php

    protected $routeMiddleware = [
        .
        .
        'revalidate' => \App\Http\Middleware\RevalidateBackHistory::class,
        .
        .
    ];
    

    Update the route in Web.php. In my case.

    Route::group(['middleware' => 'revalidate'], function(){
        Route::get('/', 'HomeController@index');
        Route::get('/home', 'HomeController@index');
        Route::get('/dashboard', 'HomeController@index');
    });
    

    And that’s all! So basically you just need to call revalidate middleware for routes which require user authentication.

    Here is the url's I followed

    Prevent Browser's Back Button Login After Logout in Laravel 5

    https://www.youtube.com/watch?v=wLkA1g2s65U

提交回复
热议问题