简体   繁体   English

405(不允许的方法)

[英]405 (Method Not Allowed)

getting an error when i try to update .... PUT http://127.0.0.1:8000/api/task 405 (Method Not Allowed), can someone help?当我尝试更新时出现错误.... PUT http://127.0.0.1:8000/api/task 405(不允许的方法),有人可以帮忙吗?

public function update(Request $request, $id)
{
     $currentUser = JWTAuth::parseToken()->authenticate();

     $task = $currentUser->tasks()->find($id);

     if(!$task)
     throw new NotFoundHttpException;

      $task->fill($request->all());

      if($task->save())
            return $this->response->noContent();
      else
         return $this->response->error('could_not_update_task', 500);
}

The methodNotAllowed exception indicates that a route doesn't exist for the HTTP method you are requesting. methodNotAllowed异常表示您请求的 HTTP 方法不存在路由。

this route http://127.0.0.1:8000/api/task looks like a store route这条路线http://127.0.0.1:8000/api/task看起来像一条商店路线

Update will be like http://127.0.0.1:8000/api/task/1更新将类似于http://127.0.0.1:8000/api/task/1

so make sure you have added the route for method所以确保你已经添加了方法的路由

感谢大家的帮助,在 hack 和 hack 之后,我意识到我的 Restangular.one("api/task").customPUT(data, taskId).then(function (response) FUNCTION 没有接收数据,所以 PUT 正在点击没有数据的 api 路由导致不允许的方法错误。

Note: Since HTML forms only support POST and GET, PUT and DELETE methods will be spoofed by automatically adding a _method hidden field to your form.注意:由于 HTML 表单仅支持 POST 和 GET,PUT 和 DELETE 方法将通过自动向表单添加 _method 隐藏字段来欺骗。 ( Laravel Docs ) ( Laravel 文档)

Can you use GET or POST method?您可以使用GETPOST方法吗?

or

{!! Form::open(array('url' => '/', 'method' => 'PUT', 'class'=>'col-md-12')) !!} .... wathever code here {!! Form::close() !!}

something like this.像这样的东西。 Hope this help希望这有帮助

EDIT: I just saw your route and your controller.编辑:我刚刚看到你的路线和你的控制器。 It expects a slug or unique identifier (which in case is id), so your route must look something like this它需要一个 slug 或唯一标识符(如果是 id),所以你的路线必须看起来像这样

Route::put('/api/task/{id}', 'YourController@update');

This gives your controller the unique identifier you want.这为您的控制器提供了您想要的唯一标识符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM