Laravel FormRequest上的PUT请求失败

时间:2019-03-25 19:47:46

标签: php laravel

我正在使用Laravel 5.8构建RESTful API,我正在使用FormRequests来验证用户输入到我的POST&PUT请求中。 POST绝对可以完美运行,但是PUT请求失败并显示以下错误,

  

“ message”:“函数App \ Http \ Requests \ ProjectStoreRequest :: Illuminate \ Foundation \ Providers \ {closure}()的参数太少,已传递0个且恰好期望1个”

我的PUT请求路由的方法如下(URL为/ api / projects / {id}),

public function update(ProjectStoreRequest $request, $id)
{
     $validated = $request->validate();
     $project  = Project::find($id);

     $project->title = $request->title;
     $project->due_date = Carbon::parse(strtotime($request->due_date))->format('Y-m-d');

     $project->save();

     return response()->json(['message' => 'Project updated', 'data' => $project], 200);
}

ProjectStoreRequest看起来像这样,

    class ProjectStoreRequest extends FormRequest
    {
       /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
       public function authorize()
       {
           return true;
       }

       /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
       public function rules()
       {
           return [
               'title' => 'required|string',
               'due_date' => 'date'
           ];
       }
   }

0 个答案:

没有答案