Answer the question
In order to leave comments, you need to log in
No query results for model, ajax single row delete Laravel 5.3?
Ajax request:
$(document).on('click', '.delete_single', function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax({
url: "/product/"+id+"/delete",
type: 'delete',
data: {
"id": id,
"_method": 'delete',
"_token": token,
},
success: function ( response ){
console.log("Success! Row deleted.");
},
error: function(){
console.log("ERROR!");
},
});
$(this).parents('tr').remove();
});
Route::delete( 'product/{product_id}/delete', '[email protected]' );
public function delete(Product $product)
{
if( exists( $product ) && !empty( $product ) )
{
$product->delete();
}
}
Route::model('product_id ', Product::class);
Answer the question
In order to leave comments, you need to log in
1. Not easier to add an attribute to .delete_single
data-delete="{{ route('products.delete', ['product' => $product]) }}"
and then use it in a query? type: "DELETE"
? exists( $product ) && !empty( $product )
- why is this? Laravel itself checks the existence of a record in the database with the passed id return response()->json($product->delete())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question