How To Add A Beautiful Delete Confirmation Message In Laravel

In our third tutorial in this series, we have added in our admin panel a delete button to delete one message. The problem here is that when we click on that button, it directly deletes the message without asking us to confirm the deletion. In this tutorial, we’ll add a beautiful confirmation message box to that button before deleting that entry.

This blog post is a part of a series that introduces you to the Laravel world by building a simple contact form protected by Google ReCaptcha and an admin panel to manage messages sent through our contact form.

To follow us along this tutorial, download the source code we produced in the previous tutorial here. We advise you to read the previous tutorial if you are confused because the dependencies we are using here have been added in the previous tutorial. By dependencies, I talk about JQuery and Sweetalert2.

The list-messages.blade.php view file

Open the file resources/views/list-messages.blade.php and add the following script to the script section.

Also, modify the delete button from the following code:

<form method="post" action="{{ url('/admin/messages/' . $message->id . '/delete') }}" style="display:inline">

    {{ method_field('DELETE') }}

     @csrf
     <button type='submit' class="btn btn-danger btn-sm">Delete</button>
 </form>

To the following one:

<form method="post" class="delete-message"
 data-route="{{ url('/admin/messages/' . $message->id . '/delete') }}"
                                        style="display:inline">
    <button type='submit' class="btn btn-danger btn-sm">Delete</button>
</form>

The app/Http/Controllers/ContactController.php file

To finish, modify the delete_message method from:

  public function delete_message($id)
    {
        $message = Contact::find($id);

        if ($message) {
            $message->delete();
        }
        return redirect('/admin/view-messages');
    }

To

  public function delete_message($id)
   {
        $message = Contact::find($id);

        if ($message) {
            $message->delete();
        }
        return response('Message delete successfully', 200);
    }

Testing

Start your development server with the command php artisan serve and try this feature in your admin panel

Conclusion

In this tutorial, we have explained how to add a beautiful confirmation delete message to our delete message buttons. If you encounter a problem at any step and need more explanation, just leave a comment below. The complete code for this tutorial is found here.

If development isn’t your field, consider hiring Laravel specialists who can supercharge your application’s scalability and performance with precision.

7 thoughts on “How To Add A Beautiful Delete Confirmation Message In Laravel

Leave a Reply

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

Back to top
porn by force indianhub.me indian girls fuck photos
kannada auntys sex videos ounoun.com indian local sex videos com
kolkata teen sex indianporncave.mobi telugu xxx .com
gotporn redwap3.com indian men naked
m taxi 69 hotindiantube.net incent porn
indian awesome sex tryporn.net xnll
gand porn analpornstars.info xnxx jabardasti
dj-punjab.in xxxvideohd.info mp3 hindi mp3
home sex malayalam pornstarsporn.info indian sex vid
download indian girl sex video indiapornfilm.pro desi xvedios
ndiansex babezporn.com unexpected sex
xvideo plumber xxx-tube-list.net kannada real sex
sexy video rap arabpornsamples.com poonam pandey xvideo
softcore 69 tryporno.net fuck.sc
shemalexnxx screwmyindianwife.info desi choda video