0

Mailgun is suppose to send a post request to laravel application, everytime it sends such request Laravel stops the request with the error

throw new Illuminate\Session\TokenMismatchException;

I can't figure out a method to solve this issue?

I am using laravel 4.1

Marwelln
  • 28,492
  • 21
  • 93
  • 117
Mohammad Abu Musa
  • 1,117
  • 2
  • 10
  • 32
  • 2
    Looks like you may have a global filter set up on all POST requests that passes the request through 'csrf' before filter. Doing so checks that the token passed in the POST data matches the one Laravel has - in the case of a request from Mailgun, there won't be a token. You need to ensure the 'csrf' filter does not apply to this route. – alexrussell Mar 31 '14 at 13:31
  • I did that and removed the filter thanks – Mohammad Abu Musa Mar 31 '14 at 14:21
  • @MohammadAbuMusa would be best to provide the solution that you implemented so that others can reference it, thanks. – Eugene Oct 11 '18 at 12:09

1 Answers1

0

Exclude the routes by adding their URIs to the $except property of the VerifyCsrfToken

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'stripe/*',
        'http://example.com/foo/bar',
        'http://example.com/foo/*',
    ];
}
Eugene
  • 473
  • 1
  • 9
  • 15