Reputation: 819
i want to delete one row from database but I am getting an error. Here's my code. How to delete that?
Route::resource('x', 'xController', ['only' => [
'index', 'store', 'destroy'
]]);
<a href="{{ action('xController@destroy', $x->id) }}" class="btn btn-danger">Delete</a>
MethodNotAllowedHttpException in RouteCollection.php line 218:
Upvotes: 1
Views: 57
Reputation: 163748
You need to use a form with DELETE
method since you're using resource controller.
<form method="POST" action="{{ action('xController@destroy', $x->id) }}">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<input type="submit" value="Delete" class="btn btn-danger">
</form>
Upvotes: 0
Reputation: 2356
You need to use Form Method Spoofing,
<form action="/foo/bar" method="POST">
{{ method_field('DELETE') }}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
HTML forms do not support
PUT
,PATCH
orDELETE
actions. So, when definingPUT
,PATCH
orDELETE
routes that are called from an HTML form, you will need to add a hidden_method
field to the form. The value sent with the_method
field will be used as the HTTP request method.
Upvotes: 1