此路由不支持 PUT 方法。支持的方法:GET、HEAD、POST
The PUT method is not supported for this route. Supported methods: GET, HEAD, POST
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:
路线::资源('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?
您可以尝试表单方法欺骗:
https://laravel.com/docs/5.8/routing#form-method-spoofing
您的路线中缺少一个参数。当您使用 http://127.0.0.1:8000/api/cook
时,它猜测您正在尝试使用 index
方法或 store
方法。因此,在您的路线中添加一个 id 参数,它应该可以与 PUT
方法一起使用。
http://127.0.0.1:8000/api/cook/1
(未测试,但应该可以)
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:
路线::资源('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?
您可以尝试表单方法欺骗: https://laravel.com/docs/5.8/routing#form-method-spoofing
您的路线中缺少一个参数。当您使用 http://127.0.0.1:8000/api/cook
时,它猜测您正在尝试使用 index
方法或 store
方法。因此,在您的路线中添加一个 id 参数,它应该可以与 PUT
方法一起使用。
http://127.0.0.1:8000/api/cook/1
(未测试,但应该可以)