use Delete verb always. You dont want anything on the server changing in response to a GET. So, yes, use a form.
Aug 17, 2018
2
Level 7
Destroy resource route: anchor + GET vs form + DELETE
Hey guys,
I'm just having a hard time trying to decide which rule i'll follow for my delete requests. I think both methods would be ok.
Going for the anchor + GET is the fastest and cleanest method but also i would be making get requests for an action that should be delete. Using a small form with DELETE would be the correct syntax (i think) but i don't like placing too many forms.
Which do you think is better?
// 1. anchor + get
// view
<td>
<a href="{{ route('model.destroy') }}">Delete record</a>
</td>
// controller
Route::get('/model/{id}/destroy', 'ModelController@destroy')->name('model.destroy');
// 2. form + delete
// view
<td>
<button class="dropdown-item" onclick="event.preventDefault();
document.getElementById('destroy-form').submit();">
Delete record
</button>
<form id="destroy-form" action="{{ route('model.destroy') }}" style="display: none;">
@method('DELETE')
@csrf
</form>
</td>
// controller
Route::delete('/model/{id}/destroy', 'ModelController@destroy')->name('model.destroy');
Thanks!
Level 122
1 like
Please or to participate in this conversation.