我试图在图像表中插入,但是以下语法显示了保存方法不会退出:Macroable.php第74行中的BadMethodCallException:
控制器:
foreach ($request->file('image') as $i)
{
$image = new image();
$image = $i;
$input['imagename'] = $request->vname.'_'.$user->id.'_'.str_random(2).'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/images');
//move image to folder
$image->move($destinationPath, $input['imagename']);
$image->title=$input['imagename'];
$image->filepath=$destinationPath;
$image->Vehicle_id=$vehicles->id;
$image->save();
}
谁能告诉我我在做什么错?
这样就可以了。
您在此处用file替换了模型的对象,$image = $i;
因此没有可用的save方法$image
。
foreach ($request->file('image') as $file)
{
$image = new image();
$input['imagename'] = $request->vname.'_'.$user->id.'_'.str_random(2).'.'.$file->getClientOriginalExtension();
$destinationPath = public_path('/images');
//move image to folder
$file->move($destinationPath, $input['imagename']);
$image->title=$input['imagename'];
$image->filepath=$destinationPath;
$image->Vehicle_id=$vehicles->id;
$image->save();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句