问题
I want to use delete route in my laravel project.
like and want to send route from href of a anchor tag.
is it possible to use delete method in route from "href" of anchor tag
Route::delete('/news/{id}', 'NewsController@destroy');
回答1:
You can't use anchor tag with href to send the request to delete. You need a form todo so. With a method DELETE since in form we have only get and post so create a hidden field with name _method and value DELETE Create form similar to this :
<form action="news/id" method="post">
<input type="hidden" name="token" value="{{csrf_token}}" >
<input type="hidden" name="_method" value="DELETE" >
<input type="submit" value="delete " >
</form>
回答2:
Route::resource('/news/{id}', 'NewsController@destroy');
and then select post, put, delete ...
来源:https://stackoverflow.com/questions/36621332/how-to-use-delete-method-in-route-in-laravel-5-2