Delete confirmation passes wrong user id in laravel, how to fix it?

I want that implement delete confirmation in laravel app when click on delete button. it works fine if there is no confirm dialoge, but does not work when I add javascript confirmation code.

here is my blade file

   <a href="{{ route('user.destroy', $user->id)}}" class="dropdown-item" onclick="
        var result = confirm('are you sure delete this?');
        if (result) {
            document.getElementById('delete_user').submit();
        }
        event.preventDefault();

        "><i class="icon-bin text-danger"></i> Delete</a>

      <form id="delete_user" action="{{ route('user.destroy', $user->id)}}" method="POST">
        @method('DELETE')
        @csrf
      </form>

75 thoughts on “Delete confirmation passes wrong user id in laravel, how to fix it?”

  1. Thanks for ones marvelous posting! I certainly enjoyed reading it, you may be a great author.
    I will ensure that I bookmark your blog and will often come
    back later in life. I want to encourage one to continue your great job, have a nice holiday weekend!

    Reply
  2. Hey there would you mind stating which blog platform you’re
    working with? I’m going to start my own blog soon but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different
    then most blogs and I’m looking for something completely unique.
    P.S Sorry for being off-topic but I had to ask!

    Reply
  3. Hey There. I discovered your weblog the use of msn. This is a really well written article.
    I will be sure to bookmark it and return to
    read extra of your useful information. Thank you for the post.
    I will definitely comeback.

    Reply
  4. I really like your blog.. very nice colors & theme.
    Did you create this website yourself or did
    you hire someone to do it for you? Plz respond as
    I’m looking to create my own blog and would like to find out where u
    got this from. thank you

    Reply
  5. Undeniably believe that which you stated.

    Your favorite justification seemed to be on the net the simplest thing to be aware of.
    I say to you, I certainly get annoyed while people think about worries
    that they just don’t know about. You managed to hit the nail upon the top and
    defined out the whole thing without having side-effects
    , people could take a signal. Will likely be back to get more.
    Thanks quest bars http://bit.ly/3jZgEA2 quest bars

    Reply

Leave a Comment