phphtmllaravelnamed-routing

Laravel pass multiple parameters to named route


I've gotten stuck on a passing additional parameters to a named route. I have found how to do it on Laravel doc's as well as an answer on Stack Overflow answer.

My problem is I cannot get to my delete function in the controller, when I click the link the page refreshes and throws no errors but does not get to the controller.

What could be wrong with my route?

Route:

Route::delete('/assets/{asset}/{model}', 'AssetManagmentController@destroy')->name('asset.delete');

Href:

<td data-label="Destroy:"><a href="{{ route('asset.delete', ['asset' => $row->id, 'model' => $key] ) }}" data-method="DELETE" data-destoy='destroy' name="delete_item">Destroy</a></td>

<td data-label="Destroy:"><a href="{{ route('asset.delete', ['asset' => 'id', 'model' => 'model'] ) }}" data-method="DELETE" data-destoy='destroy' name="delete_item">Destroy</a></td>

Solution

  • data-method="DELETE" will not magically make your link do a DELETE request. Anchor tags can only send GET requests.

    You will either have to create a GET route that can be used with an anchor tag, or create a form that can be spoofed to send a DELETE request.