有人可以帮助我解决此错误吗?当我尝试更新帖子时会发生这种情况, 这是我的更新功能
public function update(Requests\PostRequest $request, $id)
{
$post = Post::findOrFail($id);
$data = $this->handleRequest($request);
$post->update($data);
return redirect('/blog/post')->with('message','Your posts was updated successfully');
}
这是我的handleRequest函数
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 :(得分:0)
您正在访问collection
实例,需要访问基础模型:
foreach($post as $p){//loop through an Eloquent collection instance
$p->fill($data);//mass assign the new values
$p->save();//save the instance
}