Answer the question
In order to leave comments, you need to log in
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails... Laravel 5.3?
Ajax:
$(document).on('click', '#mass_delete', function( ) {
var values = [];
var token = $(this).data('token');
$('input[type="checkbox"]:checked').each(function() {
if( $.isNumeric( $(this).val() ) ){
values.push( $(this).val() );
}
});
// alert(values);
$.ajax({
url: 'products/mass_delete',
type: 'delete',
data: {
"delete_ids": values,
"_method": 'DELETE',
"_token": token,
},
})
.done(function( response ) {
console.log("Success! Rows deleted.");
})
.fail(function() {
console.log("ERROR!!!");
})
$('input[type="checkbox"]:checked').each(function() {
$(this).parents('tr').remove();
});
});
Route::delete( 'products/mass_delete', '[email protected]_delete' );
public function mass_delete(Request $request){
$product_ids = $request->get('delete_ids');
if ( is_array( $product_ids ) && !empty( $product_ids ) ) {
Product::destroy( $product_ids );
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question