1
votes

I am trying to update images in my database.I am using laravel 5.4 version. I am getting this error.

Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::make() must be of the type array, object given, called in C:\xampp\htdocs\laravel_eshopper\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 1357

Here is my update function in the controller script. enter image description here

2

2 Answers

3
votes

if use http://image.intervention.io/

Change Product::make($image) to Image::make($image)

0
votes

Ah okay I know the problem. First, the best practice is not save the image in database just save the path where you save the image.

Here I give you example code:

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;

}