Created
June 15, 2020 02:12
-
-
Save elenakondrateva/8b719d360c345a726fc98cee67cfb9cb to your computer and use it in GitHub Desktop.
Enable Postman requests in Laravel (exception for CSRF Middleware)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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