error when uploading image with laravel?

3

I have a form in which I save an image, I save the image in the folder successfully, but the new image path with its new name is not saved in the database.
Save something like:

 "C:\xampp\tmp\php71AA.tmp"'

This is the part I use to get the new address:

 $input -> imagen_producto = asset($path);

Here I leave the driver code.

public function store(CreateproductoRequest $request)
{

$input = $request->all();

if($request->file('imagen_producto'))
{
$path = Storage::disk('public')->put('image',$request->file('imagen_producto'));
$input -> imagen_producto = asset($path);
  }

    $producto = $this->productoRepository->create($input);
    Flash::success('Producto saved successfully.');
    return redirect(route('producto.index'));
}
    
asked by Neftalí García 24.09.2018 в 19:08
source

2 answers

3

Ready Change this line:

$input -> imagen_producto = asset($path);

For this:

$input['imagen_producto'] = $path;

These lines keep the new name of the image. In the first line with "asset" I got the name and the complete address of where the uploaded image is. In the second line, I get the name of the directory where I saved the image and the name of it. But in the first line it did not save anything in the object of the form "image_product", in the second one if it saves correctly the new name of the image. However, I decided not to use "asset" although I could use it.

    
answered by 25.09.2018 / 02:06
source
0

In your database you should save only the name of your image and then access it with {{asset ('directory' / 'image name')}}. In image name you must rescue what is stored in the database

    
answered by 24.09.2018 в 22:15