Код: Выделить всё
// 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);
});
});
Код: Выделить всё
{
"success": true,
"sayi": "123"
}
Код: Выделить всё
{
"success": true,
"sayi": null
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... in-laravel
Мобильная версия