softya
softya

Reputation: 260

Laravel CSRF protection exception now working

My Laravel project is in this link

http://localhost/demo/public // laravel project

and I have this external HTML form

http://localhost/attendance

Now I want to send data from the form to Laravel but I got this error

419 Page Expired

so in my laravel project VerifyCsrfToken Class I wrote this

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'http://localhost/attendance'
    ];
}

but still, got the same error

419 Page Expired

Upvotes: 1

Views: 1030

Answers (2)

Thamer
Thamer

Reputation: 1954

Laravel resolve for you the baseUrl of your application, there is no need to put the full path, in your case the Middleware should be like below:

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'attendance/*'
    ];
}

Upvotes: 3

N69S
N69S

Reputation: 17205

  • One solution would be to send the data as a GET request instead of a POST one.

  • Once you put your work online, you would face cross-site protection on the browser.

  • The URI to be excluded is the one receiving the request so http://localhost/demo/public

Upvotes: 1

Related Questions