user image

Jo Micheal
Published in : 2022-08-03

Laravel API POST method returns 419


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?



Mohamed Atef Date : 2022-08-03

Best answers


Best answers


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

I want to make multiple foreign keys in Laravel, can I?
Publish date: 2022-01-27 | Comments: 5
How can I validate recaptcha in Livewire class ??
Publish date: 2022-02-23 | Comments: 2
Laravel Network is unreachable stream_socket_client 587
Publish date: 2022-02-16 | Comments: 4
[solved] Class "App\Exceptions\Client" not found
Publish date: 2022-02-09 | Comments: 2
Laravel redirect to the last location after login
Publish date: 2022-02-21 | Comments: 1