I am building a form with laravel 5.6 and where I save a name and a user photo, but i need the photo to be stored with the username. I show the code of my store
public function store(Request $request) { $entrada=$request->all(); if($archivo=$request->file('foto_dni')){ $nombre=$archivo->getClientOriginalName(); $archivo->move('fotosdni', $nombre); $entrada['foto_dni']=$nombre; } Persona::create($entrada); }
I can get the username with $request->nombre;
but I don’t know how to assign that name to the photo
Advertisement
Answer
There is a ->storeAs()
method available on the Laravel’s request object.
You can use it like:
$path = $request->file('foto_dni')->storeAs( 'YOUR_FILE_PATH', 'YOUR_FILE_NAME' );