方法保存不存在。 Laravel

时间:2017-01-13 08:52:56

标签: php laravel save

我正在尝试在图像表中插入但是后面的语法显示方法保存不会退出: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();

}

谁能告诉我,我做错了什么?

1 个答案:

答案 0 :(得分:3)

这将完成这项工作。

您在此处使用文件$image = $i;替换了模型的对象,因此$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();

}
相关问题