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=FALSE
on .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.
CodePudding user response:
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
CodePudding user response:
php artisan optimize
Run the Command