sweet alert confirm box in laravel

Pinterest LinkedIn Tumblr

SweetAlert is a JavaScript library that can be used to create beautiful and functional confirm boxes in a Laravel application.

To use SweetAlert in a Laravel application, you will first need to include the SweetAlert library in your project. You can do this by installing it through npm or yarn and then adding it to your project’s JavaScript files.

Copy codenpm install sweetalert


Copy codeyarn add sweetalert

Then you can import it in your app.js or bootstrap.js file.

Copy codeimport Swal from 'sweetalert';

Once you have SweetAlert included in your project, you can use it to create a confirm box in your Laravel application. Here’s an example of how you might use SweetAlert to create a confirm box that will delete a resource:

Copy code<button onclick="{
    title: 'Are you sure?',
    text: 'You will not be able to recover this imaginary file!',
    type: 'warning',
    showCancelButton: true,
    confirmButtonText: 'Yes, delete it!',
    cancelButtonText: 'No, keep it'
  }).then((result) => {
    if (result.value) {
        'Your imaginary file has been deleted.',
      // Call your delete method
    } else if (result.dismiss === Swal.DismissReason.cancel) {

Write A Comment