How to delete confirmation in laravel

0 votes

I have the following code:

@foreach($results as $result)
  <tr>
    <td>{{$result->my_id}}</td>
    <td>{{$result->province_name}}</td>
    <td>{{$result->city_name}}</td>
    <td>
      <a class="btn btn-primary" href="{{route('city-edit', $result->my_id)}}"><i class="fa fa-edit"></i></a>
      <a class="btn btn-danger" href="{{route('city-delete', $result->my_id)}}"><i class="fa fa-trash"></i></a>
    </td>
  </tr>
@endforeach

How to add a confirmation on delete each data?

Dec 4, 2020 in Laravel by kartik
• 37,510 points
70 views

1 answer to this question.

0 votes

Hello @kartik,

If this is your link:

<a href="#" class="delete" data-confirm="Are you sure to delete this item?">Delete</a>

Use this Javascript:

var deleteLinks = document.querySelectorAll('.delete');

for (var i = 0; i < deleteLinks.length; i++) {
    deleteLinks[i].addEventListener('click', function(event) {
        event.preventDefault();

        var choice = confirm(this.getAttribute('data-confirm'));

        if (choice) {
            window.location.href = this.getAttribute('href');
        }
    });
}

Hope it helps!!

Thank you!!

answered Dec 4, 2020 by Niroj
• 82,720 points

Related Questions In Laravel

0 votes
1 answer

How to delete a single record in Laravel 5?

Hello @kartik, Delete an existing Model $user = User::find(1); $user->delete(); Deleting ...READ MORE

answered Dec 2, 2020 in Laravel by Niroj
• 82,720 points
188 views
0 votes
1 answer

How to delete queued jobs in laravel?

Hello @kartik, Restart Beanstalk: sudo service beanstalkd restart ...READ MORE

answered Dec 2, 2020 in Laravel by Niroj
• 82,720 points
514 views
0 votes
1 answer

How to pass URL param in Laravel?

Hello, First you have to go to routes ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,720 points
2,970 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,720 points
6,446 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,720 points
7,242 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,720 points
821 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,720 points
641 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,720 points
7,653 views
0 votes
2 answers

How to delete or clear caching in Laravel?

You can call an Artisan command outside ...READ MORE

answered Dec 16, 2020 in Laravel by Rajiv
• 8,880 points
41,699 views
0 votes
2 answers

How to delete file from public folder in laravel?

I just want to add @niroj answer  Use ...READ MORE

answered Nov 5, 2020 in Laravel by Helloworld
• 140 points
1,836 views