Image intervention wrong path when saving image

0

It turns out that following a tutorial to save the image I did this

 public function store(Request $request)
    {

        $file = Input::file('imagen1');
        $image = \Image::make(\Input::file('imagen1'));
        $path = public_path().'/thumbnails/';

        $image->save($path.$file->getClientOriginalName());
        $image->resize(null, 300, function ($constraint) {
            $constraint->aspectRatio();
        });
        $image->save($path.'thumb_'.$file->getClientOriginalName());

        $thumbnail = new Thumbnail();
        $thumbnail->image = $file->getClientOriginalName();
        $thumbnail->save();

        $request->user()->propiedades()->create($request->all());
        return redirect('profile#propiedades');
    }

And my problem is that it keeps the path of the temporary route and not the real path, so when I go to my table, it never finds the image.

The real image is saved here

So my question is how do I save it but the real path so when I go to my blade I can find the image. Thanks

    
asked by Infraganti 05.12.2016 в 00:35
source

1 answer

0

I do not know if I understand the code well but I think you need to move it to the path. I recycle a code I used a little bit.

if($request->file('imagen_1'))
    {
        //Manipulacion de imagenes
        $file= $request->file('imagen_1');
        $nombre= 'emap_1'.time().'.'.$file->getClientOriginalExtension();
        $path = public_path().'/img/articulos';
        $file->move($path,$nombre);

        $img = new Imagen(); 
        $img->nombre = $nombre;
        $img->descripcion = $request->descripcion_1;
        $img->articulo()->associate($articulo);
        $img->save();      
    }

In my case I define a full name with the function time () to randomize the name. I define my path. And with the move () function I move it.

The rest is typical of my code. I keep the name, a description and associate an article.

I hope it serves you. Greetings

    
answered by 06.12.2016 в 01:58