CRUD Laravel 5 how to link to destroy of Resource Controller?

后端 未结 10 2177
迷失自我
迷失自我 2020-12-15 17:27

I have a link



        
10条回答
  •  感情败类
    2020-12-15 17:52

    If you really want to visit the destroy action on delete route by HTML, then there is an approach to use HTTP Method Spoofing which means that you could visit a delete HTTP method by adding a hidden input named _method with the value of `"DELETE". Same way can be used for "PUT" and "PATCH" HTTP method.

    Below is a sample for DELETE method.

    will get the route

    DELETE  /tasks/{id}  destroy     tasks.destroy
    

    if you use laravel collective, you can write this way in your views.

    {!! Form::open(['url' => '/tasks/'.$cat->id, 'method' => 'delete']) !!}
    {!! Form::submit('Delete', ['class' => 'btn btn-primary']) !!}
    {!! Form::close() !!}
    

提交回复
热议问题