user image

Jo Micheal
Published in : 2022-08-03

Laravel API POST method returns 419

Laravel

Hello everybody,
I have a problem in my API Laravel 9x  it returns 419 Page Expired, However everything is fine with the request,

api.php looks like

<?phpuse Illuminate\Http\Request;use Illuminate\Support\Facades\Route;use App\Http\Controllers\authentication\UsersController;Route::controller(UsersController::class)->prefix('/user')->group(function (){ Route::post('/signup', 'create');});

Any Idea why this happen?

 

 

 

 

web-brackets.com

Comments

Mohamed Atef Date : 2022-08-03

Best answers

51

Best answers

51

Welcome Back Jo,
This issue usually happens in the new Laravel setup because you need to exclude the API routes from the middleware of CSRF verification.
you will find a file called VerifyCsrfToken.php in app/Http/middleware/VerifyCsrfToken.php you should edit the file and update the expect array to include “api/*” like this 

<?phpnamespace 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<int, string> */ protected $except = [ 'api/*' ];}

Good Luck

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

[solved] Class "App\Exceptions\Client" not found
Publish date: 2022-02-09 | Comments: 2
laravel installation error with composer install
Publish date: 2022-02-23 | Comments: 2
How can I use arabic words, paragraphs in the faker?
Publish date: 2022-03-06 | Comments: 1
How can I validate recaptcha in Livewire class ??
Publish date: 2022-02-23 | Comments: 2
Increase Sanctum token length in Laravel x9
Publish date: 2022-07-16 | Comments: 2