2017-08-07 158 views
0

我正在尝试更新数据库中的映像。我使用的是laravel 5.4版本。 我收到此错误。Laravel数据库映像更新失败

类型错误:传递给Illuminate \ Database \ Eloquent \ Builder :: make()的参数1必须是在C:\ xampp \ htdocs \ laravel_eshopper \ vendor \ laravel \ framework中调用的类型数组, \ src \ Illuminate \ Database \ Eloquent \ Model.php on line 1357

这是我在控制器脚本中的更新函数。 enter image description here

回答

2

如果使用http://image.intervention.io/

变化Product::make($image)Image::make($image)

+0

,请您提供一些解释为什么你认为上述变化将解决这个问题。这将有助于了解问题的原因,从而避免将来出现同样的错误。 –

0

没关系啊,我知道这个问题。 首先,最佳做法不是将图像保存在数据库中,而是保存保存图像的路径。

这里,我给你的示例代码:

if ($request->hasFile('image')) { 
    $image = $request->file('image'); 
    $filename = time() . '.' . $image->getClientOriginalExtension(); 
    $location = public_path('images/home/'); 

    // now saving the file 
    $image->move($location, $filename); 

    // delete oldfile 
    $oldFilaname = $product->image; 
    Storage::delete($oldFilename); 

    // update 
    $product->image = $location . '/' . $filename; 

}