How to use PUT, PATCH, DELETE in Laravel?

If you want to use HTTP Methods like PUT, PATCH, DELETE in Laravel then follow below steps.

In form section you have to put a field like below eaxample

<form class=”form-control” action=”/update” method=”post”>
{{ csrf_field() }}
{{ method_field(‘PUT’) }}
<input name=”id” type=”hidden” value=”{{ $user->id }}” />
<input name=”name” type=”text” value=”{{ $user->name }}” />
<input name=”email” type=”email” value=”{{ $user->email }}” />
<input name=”submit” type=”submit” value=”Update” />

{{ method_field(‘PUT’) }} this code generate a hidden field name _method with value PUT or DELETE or PATCH or You can manually add this hidden field in form section.

<input name="_method" type="hidden" value="PUT" />
<input name="_method" type="hidden" value="PATCH" />
<input name="_method" type="hidden" value="DELETE" />

and you have to put action routes on web.php under routes folder like below example.

Route::put('/update', 'InsertDetails@updateData');
Route::delete('/delete', 'InsertDetails@deleteData');
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *