错误
Symfony \ Component \ Debug \ Exception \ FatalThrowableError(E_RECOVERABLE_ERROR) 类型错误:参数1传递给Illuminate \ Database \ Eloquent \ Model :: __ construct()必须是类型数组,字符串给出,在第65行的mypath \ app \ Http \ Controllers \ PostsController.php中调用
控制器
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'image' => 'mimes:jpeg,png,jpg,gif,svg|max:2048',
'body' => 'required'
]);
//dd($request);
auth()->user()->publish(
Storage::putFile('images', new File($request['image']), 'public'),
new Post(request('title', 'image', 'body'))
);
session()->flash('message', 'your post has now been published');
return redirect('/');
}
...
答案 0 :(得分:3)
你需要提供请求参数来创建像这样的数组格式的新帖子,
$request->only('title', 'image', 'body')
这样你的代码就好了,
auth()->user()->publish(
Storage::putFile('images', new File($request['image']), 'public'),
Post::create($request->only('title', 'image', 'body')))
);
我希望你能理解。