Skip to content

Instantly share code, notes, and snippets.

@elenakondrateva
Created June 15, 2020 02:12
Show Gist options
  • Save elenakondrateva/8b719d360c345a726fc98cee67cfb9cb to your computer and use it in GitHub Desktop.
Save elenakondrateva/8b719d360c345a726fc98cee67cfb9cb to your computer and use it in GitHub Desktop.
Enable Postman requests in Laravel (exception for CSRF Middleware)
<?php
namespace App\Http\Middleware;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
public function __construct(Application $app, Encrypter $encrypter)
{
parent::__construct($app, $encrypter);
// enable Postman requests on local
if (app()->environment('local') && strpos(request()->header('User-Agent'), 'PostmanRuntime') === 0) {
$this->except = ['*'];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment