Problem with confirm delete, all works fine, but if you click cancel in confirm popup it will delete the item from DB. Any ideas? Please show with code example, I'm new to laravel.
<script>
function ConfirmDelete()
{
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
else
return false;
}
</script>
{!! Form::open(['method' => 'DELETE', 'route' => ['path_delete_time', $time->id], 'onsubmit' => 'ConfirmDelete()']) !!}
{!! Form::hidden('case_id', $project->id, ['class' => 'form-control']) !!}
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', array('type' => 'submit', 'class' => 'specialButton')) !!}
{!! Form::close() !!}
php. Route::get('delete-records','StudDeleteController@index'); Route::get('delete/{id}','StudDeleteController@destroy'); Step 6 −The output will appear as shown in the following image. Step 7 − Click on delete link to delete that record from database.
Laravel Eloquent Deleting To delete a model instance, retrieve it and call the delete() method: $user = User::find(1); $user->delete(); Alternatively, you can specify a primary key (or an array of primary keys) of the records you wish to delete via the destroy() method: User::destroy(1); User::destroy([1, 2, 3]);
Just add return to your onsubmit
call. so the value the function returns determines if the form gets submitted or not.
'onsubmit' => 'return ConfirmDelete()'
Simple put jQuery code for prompt box when submit form or delete record.
jQuery(document).ready(function($){
$('.deleteGroup').on('submit',function(e){
if(!confirm('Do you want to delete this item?')){
e.preventDefault();
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With