save image name in laravel database

0

I'm trying to save the name of the image in the database from Laravel, I could get the name of the file but I get an error in the code:

$name = time().'_'.$file->getClientOriginalExtension();

and then I do not know what the error is, what I have up to now is to save the image in a laravel route, and see it come out but obviously it does not work because of the error:

if ($file = $request->foto){

     $file = $request->file('foto');
     $file = $request->foto;
     $name = time().'_'.$file->getClientOriginalExtension();

     dd($name);

  }

How can I solve it?

    
asked by Juan Antonio 24.05.2018 в 20:50
source

1 answer

1
$file = $request->file('file');
            //obtenemos el nombre del archivo
            $nombre =  time()."_".$file->getClientOriginalName();
            //indicamos que queremos guardar un nuevo archivo en el disco local
            \Storage::disk('local')->put($nombre,  \File::get($file));

            $archivo = new Archivos;
            $archivo->nombre_ = $nombre;
            $archivo->save();

I hope it serves you well I do it I keep the name and the file

    
answered by 25.05.2018 в 21:41