'Laravel 9 419 Unknown Status on sending POST request
Good day, I'm having trouble on sending post data to my Laravel project, It always shows Page Expired (419) on this, Error 419 on POST
Here's the things I have done before coming up to my question:
- Added
SESSION_SECURE_COOKIE=FALSEon .env - Changed the config/session.php from
'secure' => env('SESSION_SECURE_COOKIE'),to'secure' => env('SESSION_SECURE_COOKIE', false), - Added ob_start(); at the beginning of public/index.php like this
<?php ob_start(); use Illuminate\Contracts\Http\Kernel; use Illuminate\Http\Request;
This is my route
Route::post('/data', [AdminController::class, 'getSensorData']);
Also in I'm sending the data to the database from the post request using the controller. The request works fine when the method is GET. 200ok on GET
Edit: It's working now, the fix was from @Ahmed Hassan. Thank you.
Solution 1:[1]
this issue occur because you didn't send the CSRF token with the request
just add @csrf inside your form and it will work
also, you can exclude your URL in the $except list in the App\Http\Middleware\VerifyCsrfToken
I hope it's helpful
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
