How to use patch request in Laravel?
Yes, you need to send id for route patch. Example from https://laravel.com/docs/5.4/controllers#resource-controllers for Laravel
PUT/PATCH - /photos/{photo}, so you don't need update
word in your route. Just users/id and methods PUT or PATCH.
UPD for CRUD operations:
// Routes
Route::resource('items', 'ItemsController');
// Form for update item with id=1
<form method="POST" action="{{ route('items.update', ['id' => 1])}}">
{!! csrf_field() !!}
<input name="_method" type="hidden" value="PATCH">
<!-- Your fields here -->
</form>
// Controller
public function update($id, Request $request)
{
// Validation here
$item = Item::findOrFail($id);
// Update here
}
If your route is:
Route::patch('users/update/{id}', 'UsersController@update')->name('users.update');
if you use jQuery.ajax()
for submitting data then set your method, data, and URL like this:
$.ajax({
method: "post",
url: "{{ url('/users/update/') }}" + id,
data: {"_method": "PATCH", ...}
});
if you don't use Ajax then use the following:
<form method="POST" action="{{ route('users.update',['id' => $id]) }}">
@csrf
@method('PATCH')
</form>
Update the routing as per below
Route::patch('/users/update/{id}',[
'uses' => 'UsersController@update'
]);