laravel method in href link?

后端 未结 3 716
萌比男神i
萌比男神i 2021-01-23 05:47

I want to create a dropdown with two links. A \'Delete\' and a \'Edit\' link.

For the delete function I created a form.

                        {!! Form         


        
3条回答
  •  执念已碎
    2021-01-23 06:07

    Laravel uses method spoofing to do 'DELETE', 'PUT', 'PATCH' form requests. Like @Jilson Thomas mentioned, you can just create a link directly to the route. I suspect you're using resourceful routes, thats why you're trying to post a DELETE request?

    Have a look at this section in the routing docs, this may help you out: https://laravel.com/docs/master/controllers#restful-supplementing-resource-controllers

    Based on your routes posted, I believe the following two routes are matching before it gets to your desired route.

    Route::put('/show/{id}/edit', ['as' => 'editing', 'uses' => 'Test\\TestController@update']);
    Route::delete('/show/{id}', 'Test\\TestController@destroy')->name('destroy');
    

    Try moving your desired route above these and see what happens.

    Edit

  • Delete
  • That will produce a GET request, therefore it will not match Route::delete(...). The previous method was posting a form to the route. Also, wrapping an entire form in an anchor tag is invalid markup.

提交回复
热议问题