I am trying to update a database record with ajax. The code below is returning a 404 error code.
Javascript
data = {
id: item_id,
our_cost: new_price,
_token: "{{csrf_token()}}",
};
$.ajax({
url: '/change_item_price/{id}/{our_cost}',
data: data,
type: 'POST',
success: function( data ) {
console.log(data);
}
});
Route
Route::post('/change_item_price/{id}/{our_cost}',[itemController::class, 'change_item_price'])->name('change_item_price');
Controller
public function change_item_price($id, $our_cost){
$get_id = Item::findOrFail($id);
DB::table('items')
->where('id', $get_id)
->update([
'our_cost' => $our_cost
]);
return Item::where('id',$id)->first();
}