Jo Micheal

3 Aug 2022

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


	use 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

3 Aug 2022

Best Answer

best answer

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 


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<int, string>
 protected $except = [

Good Luck

© 2024 Copyrights reserved for