Roman Miranda Roman Miranda - 1 month ago 9
PHP Question

Laravel 5.3 Upload an image with Auth user::create

I am trying to add an image to the user. To create the user I use
system make:Auth but I don't know how can I get the file name because on

create(array $data)
I don't receive the file name.

protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'img' =>
]);
}


I can't put
'img' = $data['img']
because I need the file name.

How can i get the file name?

Answer

use the getClientOriginalName method because it's symfony UploadedFile instance try this :

data['img']->getClientOriginalName();

Comments