Table of contents

integrate bootbox alert in laravel

In this post, I'm sharing how to integrate Bootbox alert & confirmation with ajax in Laravel 8. We are using Bootbox to confirm the jquery ajax delete in Laravel. When deleting records we need confirmation to prevent unexpected clicks of the delete button.


In this example, we have a controller, model, route, and blade. Just continue to read the below steps:



Route::resource('posts', PostsController::class);



* Remove the specified resource from storage.
* @param  \App\Models\Post  $post
* @return \Illuminate\Http\Response
public function destroy(Post $post)

    return response('Post deleted successfully.', 200);




namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
    protected $fillable = [

    use HasFactory;



<!DOCTYPE html>

        <meta charset="utf-8" />
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Delete Record using Ajax in Laravel 8 -</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
        <script src=""></script>
        <script src=""></script>
        <script type="text/javascript" src=""></script>
        <script type="text/javascript">
          $(document).ready(function() {

            $('.delete-form').on('submit', function(e) {
              var button = $(this);

                  title: "Are you sure?",
                  message: "Your about to delete this post!",
                  buttons: {
                      confirm: {
                          label: 'Yes',
                          className: 'btn-success'
                      cancel: {
                          label: 'No',
                          className: 'btn-danger'
                  callback: function (result) {
                    if(result) {
                        type: 'post',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        data: {
                          '_method': 'delete'
                        success: function (response, textStatus, xhr) {

                              message: response,
                              callback: function () {


        <div class="container mt-5">
            @if(Session::get('success', false))
              <?php $data = Session::get('success'); ?>
              @if (is_array($data))
                  @foreach ($data as $msg)
                      <div class="alert alert-success" role="alert">
                          <i class="fa fa-check"></i>
                          {{ $msg }}
                  <div class="alert alert-success" role="alert">
                      <i class="fa fa-check"></i>
                      {{ $data }}

            <table class="table table-striped" id="users-table">
                  <th scope="col"><input type="checkbox" class="check-all"></th>
                  <th scope="col">Title</th>
                  <th scope="col">Description</th>
                  <th scope="col">Body</th>
                  <th scope="col">Delete</th>
                @foreach($posts as $post)
                    <td><input type="checkbox" class="check"></td>
                        <form method="post" class="delete-form" data-route="{{route('posts.destroy',$post->id)}}">
                            <button type="submit" class="btn btn-danger btn-sm">Delete</button>


For more details about Bootbox visit their documentation.


That's it I hope it helps. Thank you for reading.


Cheers :)