2017-08-07 140 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; 

}