I have the following code in my controller:
public function update(Request $request, $id)
{
$cook = cooks::findOrFail($id);
if (!$cook) {
return response()->json([
'success' => false,
'message' => 'Sorry, cook with id ' . $id . ' cannot be found',
], 400);
}
$updated = $cook->fill($request->all())
->save();
if ($updated) {
return response()->json([
'success' => true,
]);
} else {
return response()->json([
'success' => false,
'message' => 'Sorry, cook could not be updated',
], 500);
}
}
And when I use in my postman method PUT I received this message "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST."
in my api.php I have the following line:
Route::resource('cook', 'cookList');
and here is the route that I use in postman:
`http://127.0.0.1:8000/api/cook`
with body id-1 and title-cook Can someone help me, please?
PUT
request?/api/cook/1
? And you should fix thecooks::findOrFail
toCook::findOrFail
– MaartenDev