I am encountering an issue when sending a PATCH request in my Laravel application. When sending a PATCH request to update a resource, I am not getting the expected result. However, when I send the same request using the POST method, I get the desired result. What could be the issue with the PATCH request?
// web
Route::patch('{id}/update', [UrunlerController::class, 'update'])->name('magaza.urun.guncelle.submit');
// Controller
public function update(Request $request, string $id)
{
$sayi = $request->input('sayi');
return response()->json([
'success' => true,
'sayi' => $sayi
]);
}
// vanilla js
document.getElementById('patates').addEventListener('click', function() {
var formData = new FormData();
formData.append('sayi', 123); // Basit veri ekliyoruz
var url = `{{ route('magaza.urun.guncelle.submit', ['id' => 8]) }}`;
fetch(url, {
method: 'PATCH',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: formData
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Hata:', error);
});
});
The result I expected
{
"success": true,
"sayi": "123"
}
The result I encountered
{
"success": true,
"sayi": null
}
Laravel v:11.20.0