Can’t delete data in Laravels

I will delete data by id but, the button is not working when I cick to delete.
I need you help.

Here’s my view

 @foreach ($books as $books)
                  <button type="button" class="btn btn-info" title="details"><i class="fa fa-info" ></i></button>
                  <button type="button" class="btn btn-warning" title="edit"><i class="fa fa-pencil" ></i></button>
                  <button type="button" class="btn btn-danger" title="delete"><i class="fa fa-trash"></i><a href ="{{ route('deletebook',[$books->id])}}" onclick="return confirm('Are you sure to delete this book?')"></a></button>

here’s my controller
 public function deleteBook($id) {
   DB::table('books')->where('id', $id)->delete();
   return redirect('home')->with('status', 'DELETE succesfully'); }

here’s my route
Route::delete('/deleteBook/{id}','<a href="" class="__cf_email__" data-cfemail="6b29040400182804051f190407070e192b0f0e070e1f0e29040400">[email protected]</a>')->name('deletebook');

I want to use button with icon like that, and i want to delete the data using that button, but when i clicked its not working. Do you have any solution?
Thank you


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try this code

At the blade (view)

<form action="{{ route('deletebook',[$books->id])}}" method="POST">
  <button type="submit" onclick="return confirm('Are you sure to delete this book?')" class="btn btn-danger"><i class="fa fa-trash"></button>

Note: The form is a display block you can change to inline by adding this class d-inline


Route::delete('/deleteBook/{book}','<a href="" class="__cf_email__" data-cfemail="b3f1dcdcd8c0f0dcddc7c1dcdfdfd6c1f3d7d6dfd6c7d6f1dcdcd8">[email protected]</a>')->name('deletebook');

//Add Book model
public function deleteBook(Book $book) {
   return redirect('home')->with('status', 'DELETE succesfully'); 

Try it, and tell me if is everything alright.

Happy Coding.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x