php - Image Uploading Laravel 5.2 : Trying to get property of non-object -
i'm trying upload images using method moving temporary files, , show on index page path.
here's problem:
errorexception in productcontroller.php line 69: trying property of non-object
in controller contain line error:
public function store(request $request) { $product=request::all(); product::create($product); $imagename = $product->id_prod . '.' . $request->file('images')->getclientoriginalextension(); $request->file('images')->move( base_path() . '/public/images/catalog/', $imagename ); return redirect('product'); }
and here's database, file has been uploaded on temp folder, file fail moved. i'm using laravel 5.2, first time upload files. , can explain me why 1 error.
sorry bad grammars.
you can try this:
public function store(request $request) { $product = $request->all(); $picture = ''; if ($request->hasfile('images')) { $file = $request->file('images'); $filename = $file->getclientoriginalname(); $extension = $file->getclientoriginalextension(); $picture = $product['id_prod'] . '.' . $extension; $destinationpath = base_path() . '/public/images/catalog/'; $request->file('images')->move($destinationpath, $picture); } if (!empty($product['images'])) { $product['images'] = $picture; } else { unset($product['images']); } product::create($product); return redirect('/product'); }
Comments
Post a Comment