How to fix delete button not working in Laravel 5.7?

I'm trying to make a delete button in Laravel, but it redirects me to a white page. this is the html code for the delete button (it's an icon):

<a class="icon" href="{{ route('capteurs.destroy', $capteur->id)}}" data-balloon="Supprimer" data-balloon-pos="right">
    <i class="fe fe-trash-2" ></i>
</a>

destroy function in the controller class:

public function destroy($id)
{
  $capteur = Capteur::find($id);
  $capteur->delete();
  return redirect('/capteurs')->with('success', 'Capteur Supprimé');
}

I'm supposed to be redirected to /capteurs which is this page:

Instead i get redirected here, and the element i wanna delete is still there:

Edit: Routes for capteurs

Route::resource('capteurs', 'CapteurController');

I think you should make a form for that:

<form method="POST" action="{{ route('capteurs.destroy', $capteur->id)}}"
  @csrf
  @method('DELETE')
  <a class="icon" data-balloon="Supprimer" data-balloon-pos="right">
  </a>
  <button type="submit"><i class="fe fe-trash-2" ></i></button>
</form>

Not working Delete Button, I am going to delete files in My laravel app. but delete button not working. (not deleted) No any Error blade.php <div class="col-md-5"&g how can solve this problem? Report Spam. tomopongrac. Level 50. Laravel File::delete() Not Working Posted 4 years ago by Arslan. I am try to delete the Image from the Directory But File::delete() Is not working. Here is my code.

You need to add a form around your anchor tag and next thing you need is a DELETE request instead of GET. You can try the below code:

<form action="{{ route('capteurs.destroy', $capteur->id) }}" method="POST">
    {{ method_field('DELETE') }}
    {{ csrf_field() }}
    <button type='submit' class="btn btn-danger" ><i class="fe fe-trash-2" ></i></button>
</form>

If you really want it to do with the anchor tag then give a specific id to your anchor tag and do an ajax request!

How to output a clickable delete button using laravel collectives in , The problem is that it outputs a raw html text {! How to output a clickable delete button using laravel collectives in yajra datatables laravel 5.7� All delete button open the modal but with confirmation it returned to list page with no delete from the list and no delete from database. public function postDelete

You're currently linking to your destroy page like its a GET request, while it should be a POST request. If execute php artisan route:list it will show information on the routes.

To fix this:

<form action="{{ URL::route('capteurs.destroy', $capteur->id) }}" method="POST">
    <input type="hidden" name="_method" value="DELETE">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <button><i class="fe fe-trash-2" ></i></button>
</form>

You'll probably have to edit styling a bit though

Delete method only delete first ID from the list using Implicit Binding , Laravel Version: 5.7 PHP Version: 7.2.7 Database Driver & Version: MySQL I try with and without pagination, same problem with pagination on page 1 but Then when the button is clicked, you get the first ID of delete-form� Hi guys, I was working on my upgrading to Laravel 5 and testing my function, I see that soft delete is not working, it deletes the raw at all from the database. I'm using SoftDeletes instead of SoftDeletingTrait in the class model, as it said in the Laravel documentation.

Middleware - Laravel, If the user is not authenticated, the middleware will redirect the user to the login @param \Closure $next * @return mixed */ public function handle($request, you should first assign the middleware a key in your app/Http/Kernel.php file. can only remove route middleware and does not apply to global middleware. As a standard practice of creating an CRUD application there are certain actions in like update and delete which requires the method submitted to the server url to be either PUT/PATCH (to modify the resource) and DELETE (for deleting the resource). This is how the standard calls look like in Laravel CRUD application. This can be easily acheived via AJAX by changing the method in your dyanamic

Routing - Laravel, Within this group, the /api URI prefix is automatically applied so you do not Any HTML forms pointing to POST , PUT , PATCH , or DELETE routes that are you may pass the parameters as the second argument to the route function. The given parameters will automatically be inserted into the URL in their correct positions: Laravel ThanhPv • 3 years ago. 5369 10. Laravel Storage:: delete() not working Posted 3 years ago by ThanhPv. Hi, I am using this methods to delete files

Session - Laravel, Master, 7.x � 6.x � 5.8 � 5.7 � 5.6 � 5.5 � 5.4 � 5.3 � 5.2, 5.1, 5.0 � 4.2 By default, Laravel is configured to use the file session driver, which will work well The Laravel framework uses the flash session key internally, so you should not add an item to the session The pull method will retrieve and delete an item from the session: Laravel 5.3 submit form does nothing :( Posted 3 years ago by esquarial In my Laravel 5.3 form when i click submit button nothing happens, it does not redirecting me anywhere, just reloading same page.

Comments
  • Could you post the routes file? (capteurs and capteurs.destroy should be enough)
  • @Stormhammer Edited!
  • I edited my answer a bit. Could you try it?
  • when you using route resource, delete endpoint would be DELETE /capteurs/{id} but you send a GET request to /capteurs/{id}