Reputation: 109
I am trying to hit a route I made to make a delete HTTP request in laravel view when user clicks on 'Delete' button, but it won't work. I've read it should be done with forms in laravel.
Here is my code:
<form action="/admin/pages/delete/{{ $section->id }}" method="post">
{{ method_field('delete') }}
<button class="btn btn-sm" type="submit">Delete</button>
</form>
What is a proper way to handle this? It shows me an error in the console, Bootbox: 'please specify a message' whenever I click on the button.
Route definition inside admin group:
Route::delete('/pages/delete/{id}', 'PagesController@delete')->name('pages.delete');
Upvotes: 0
Views: 337
Reputation: 5603
You must add the the CSRF Field because all form submission must past through the VerifyCsrfToken
middleware before the request be procede by the controller
{{ csrf_field() }} // add this before or after the {{ method_field() }}
Upvotes: 1