I am trying to update my database via a PUT method:
const eventid = arg.event.id;
const eventData = {
start: arg.event.start.toISOString(),
end: arg.event.end.toISOString(),
};
const csrfToken = document.head.querySelector("[name~=csrf-token][content]").content;
console.log(csrfToken);
fetch(`/api/event/update/${eventid}`, {
method: 'PUT',
headers: {
"X-CSRF-Token": csrfToken
},
body: encodeFormData(eventData),
})
The specific error is `PUT HTTP://localhost:8000/api/event/update/105 405 (Method not allowed). I have tried other methods but they all return similar errors. Additionally here is my Controller code:
public function update(Request $request)
{
$booking = Booking::findOrFail($request->id);
$booking->start_date = $request->start;
$booking->end_date = $request->end;
$booking->save();
return response()->json($booking);
}
Route:
Route::post('/event/update/{eventid}', [CalendarController::class, 'update']);
Is this an issue with using 'post' in my route?
PUTmethod, you need to useRoute::put('/event/update/{eventid}', [CalendarController::class, 'update']);, You could also make your methodPOST/api/event/update/${eventid}and the route is/event/update/{eventid}Is the route nested in a group forapiprefix(or api.php file)?php artisan route:listin cli to see your actual registered routes?