Reputation: 155
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.
Upvotes: 1
Views: 474
Reputation: 446
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;
}
Upvotes: 0
Reputation: 576
if use http://image.intervention.io/
Change Product::make($image)
to Image::make($image)
Upvotes: 3