Search code examples
phplaravellaravel-5.5

laravel route:any page expired to inactivity


I am using in laravel 5.5 a route for Any:

Route::any('/', 'HomeController@index')->name('homepage');

The route should be a GET one, but because of a third provider which redirect with a POST i had to change it to any;

The problem is when redirect is made from the third party (with post) now i get:

The page has expired due to inactivity. 

Please refresh and try again.

this is because of the {{ csrf_field() }}

How can i pass the csrf_field and make that route act as a GET one even if i get a POST request?


Solution

  • Note: Do not disable CSRF protection unless you know what you are doing. I only suggest this because it appears they are not actually POSTing any data to the application on this route.

    You can exclude URIs from CSRF protection by adding the URI to the $except array in the VerifyCsrfToken middleware:

    https://laravel.com/docs/5.6/csrf#csrf-excluding-uris

    protected $except = [
        '/',
    ];