【问题标题】:Method save doesnot exist. Laravel方法保存不存在。拉拉维尔
【发布时间】:2017-01-13 08:52:56
【问题描述】:

我正在尝试插入图像表,但以下语法显示方法保存不退出: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();

}

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

【问题讨论】:

  • 请添加完整的方法(包括参数)
  • 保存不存在:Macroable.php 第 74 行中的 BadMethodCallException
  • 我认为这一行,你分配了 $image = $i;
  • codeshare.io/a3kjga 完整代码。 @弗兰克教务长
  • 尝试 $image->move('paht/to/image/image.jpg') 而不是保存

标签: php laravel save


【解决方案1】:

这样就可以了。

您在这里用文件$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();

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2014-09-18
    • 1970-01-01
    • 2020-03-11
    相关资源
    最近更新 更多