laravel 5调用未定义的方法Illuminate \ Database \ Query \ Builder :: posts()

时间:2017-08-01 13:25:26

标签: laravel-5 undefined query-builder

我想存储此信息,但这不起作用我仍然有此错误“调用未定义的方法Illuminate \ Database \ Query \ Builder :: posts() “

公共功能商店(请求$请求)     {

      $this->validate($request,[
       'title'=>'required',
        'slug'=>'required',
        'excerpt'=>'required',
        'body'=>'required',
        'created_at'=>'date_format:Y-m-d H:i:s',
        'team_id'=>'required',
        'image'=>'mimes:jpg,jpeg,png,bmp',

    ]);



    $data = $this->handleRequest($request);

    $request->user()->posts()->create($data);

    return redirect('/backend/blog')->with('message', 'Your post was created successfully!');
}

private function handleRequest($request)
{
    $data = $request->all();

    if ($request->hasFile('image'))
    {
        $image       = $request->file('image');
        $fileName    = $image->getClientOriginalName();
        $destination = $this->uploadPath;

        $image->move($destination, $fileName);

        $data['image'] = $fileName;
    }

    return $data;
 }

0 个答案:

没有答案