What's in VehiclesRequest class? Form request classes have authorize() method, do you have anything there?
403 Unauthorized on PUT Request sanctum
I am currently creating a small mobile app, for the backend i decided to make a stateless laravel API, for authentication i use the Tokenbased middleware auth:sanctum, which works perfectly fine for GET and POST request, for testing the API i use Postman and i use MAMP as my local database. But i ran into the problem that PUT and PATCH requests don't work. I will just get a 403 Forbidden
"message": "This action is unauthorized.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException",
"file": "C:\\MAMP\\htdocs\\laravel\\pickerl-reminder\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\Handler.php",
"line": 673,
"trace": [
When i change the Route to POST it works. And yes i always match the request type in Postman and the api.php for the Routes, so i do not send PUT in postman for a POST Route. I also already checked and Postman is sending the token with the request
Route::middleware('auth:sanctum')->group(function () {
Route::get("/vehicle/{vehicles}", [VehiclesController::class, "show"])->name("vehicles.show");
Route::put("/vehicle/{vehicles}", [VehiclesController::class, "update"])->name("vehicles.update");
});
Like i said the GET route works as wanted,
public function update(VehiclesRequest $request, Vehicles $vehicles)
{
\Log::debug($vehicles);
$this->authorize('update', $vehicles);
$vehicles->update($request->validated());
return new VehiclesResource($vehicles);
}
This is the update function, i don't even see the Log in laravel.log, so this function is not even called when it's a PUT route.
I hope it is clear what i mean and what the problem is. Thanks already to anyone trying to help
Please or to participate in this conversation.