I want to use destroy method on laravel to delete an existing item for the user. Normally, one would use a route::put or patch along with the form to mask the submit button to send the delete request.
I was wondering if I have a delete icon and I can use anchor tag with route to perform the request like below:
Blade view:
<div class="row">
<div class="offset-2 col-5">
<a href="{{route('shop.perfect-list.destroy',[$item->product->global_product_id])}}"> <i class="fa fa-trash-o fa-2x text-muted mt-4 padding-left-icon"></i></a>
</div>
</div>
Route:
Route::put('/remove/{product_id}','Shop\WishListController@destroy')->name('shop.perfect-list.destroy');
Controller:
//Remove the specified item from storage.
public function destroy($product_id){
$userID = Auth::user()->id;
$perfectList = new Favorite;
$perfectList = $perfectList->where('user_id',$userID)->where('product_id',$product_id)->first();
dd($perfectList);
}
Of course running this gives me the error:
The GET method is not supported for this route. Supported methods: PUT.
Since I am not masking a @csrf into my blade.
Any alternatives or suggestion I could use?