jQuery Delete Confirm in Laravel 5.7 Example

jQuery Delete Confirm in Laravel 5.7 Example

Today, We want to share with you jQuery Delete Confirm in Laravel 5.7 Example.In this post we will show you sweet alert delete confirmation laravel, hear for Laravel 5 – Confirmation before delete record from database we will give you demo and example for implement.In this post, we will learn about show confirmation prompt while deleting row in Laravel with an example.

jQuery Delete Confirm in Laravel 5.7 Example

There are the Following The simple About jQuery Delete Confirm in Laravel 5.7 Example Full Information With Example and source code.

Read Also:  Toopics instagram viewer

As I will cover this Post with live Working example to develop Laravel Prompt before deleting Confirm, so the Laravel 5.7 – Delete Confirm Bootstrap jQuery Model for this example is following below.

HTML for delete button

If you display below Laravel source code for Confirmation before deleting an item, $products is iterable Data object, its generating likes for all the available each products.

<h2>show confirmation prompt while deleting row in PHP Laravel.</h2>
@foreach ($products as $product)
    <form class="delete" action="{{ route('product.destroy', $product->id) }}" method="POST">
        <input type="hidden" name="_method" value="DELETE">
        <input type="hidden" name="_token" value="{{ csrf_token() }}" />
        <input type="submit" value="Delete">
    </form>
@endforeach

Javascript to show the confirm prompt

Place below javaScript in your main Blade page footer area.

Read Also:  jquery next sibling with class

<script>
    $(".delete").on("submit", function(){
        return confirm("Do you want to delete this product?");
    });
</script>

Example 2: Modal delete confirmation Laravel

HTML delete button

<a href="javascript:;" data-toggle="modal" onclick="deleteProductData({{$value->id}})" 
data-target="#DeleteModal" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> Delete</a>

Add bootstrap modal

 <div id="DeleteModal" class="modal fade text-danger" role="dialog">
   <div class="modal-dialog ">
     <!-- Modal content for Laravel bootstrap delete confirm-->
     <form action="" id="productForm" method="post">
         <div class="modal-content">
             <div class="modal-header bg-danger">
                 <button type="button" class="close" data-dismiss="modal">×</button>
                 <h4 class="modal-title text-center">DELETE CONFIRMATION</h4>
             </div>
             <div class="modal-body">
             <p>Laravel 5.7 - Confirmation before delete record from database example</p>
                 {{ csrf_field() }}
                 {{ method_field('DELETE') }}
                 <p class="text-center">Are You Sure Want To this Product Delete ?</p>
             </div>
             <div class="modal-footer">
                 <center>
                     <button type="button" class="btn btn-success" data-dismiss="modal">Cancel</button>
                     <button type="submit" name="" class="btn btn-danger" data-dismiss="modal" onclick="ProductFormSubmit()">Yes, Delete</button>
                 </center>
             </div>
         </div>
     </form>
   </div>
  </div>

JavaScript Source Code

  <script type="text/javascript">
     function deleteProductData(id)
     {
         var id = id;
         var url = '{{ route("product.destroy", ":id") }}';
         url = url.replace(':id', id);
         $("#productForm").attr('action', url);
     }

     function ProductFormSubmit()
     {
         $("#productForm").submit();
     }
  </script>

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  PHP Include and Require commands

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about jQuery Delete Confirm in Laravel 5.7 Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *