这里是 laravel 的新手。 我正在尝试将图像保存在模型和项目的文件夹中。似乎它只保存在文件夹中,但在 Macroable.php 第 74 行返回 BadMethodCallException:方法保存不存在。 每当我将它保存到数据库时。非常感谢任何帮助!
public function itemPicture(Request $request)
{
if($request->hasFile('itemPic'))
{
$bfItemPic = $request->file('itemPic');
$filename = /*time() . '.' . */ $bfItemPic->getClientOriginalName();
Image::make($bfItemPic)->resize(250,250)->save( public_path('/itempictures/' .$filename));
//bufashItems::create($request->all());
$bfproducts = bufashItems::all();
$bfproducts->item_picture = $filename;
$bfproducts->save();
}
return redirect('/Items');
}
最佳答案
您收到此错误是因为您尝试对集合使用 save()
方法。你应该得到一个对象来让它工作,例如:
$bfproducts = bufashItems::where('id', 5)->first();
$bfproducts->item_picture = $filename;
$bfproducts->save();
关于php - 方法save()在使用图像介入时不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43034536/