Did you add it in $fillablearray in User model ?
Adding picture when register
Hi,
So, I'd like that, when a user register, he can add a profile picture. I made the new input in the template and I filled the create method in AuthController.php :
protected function create(array $data) {
$fileName = 'null';
if (Input::file('image')->isValid()) {
$destinationPath = public_path('uploads/files');
$extension = Input::file('image')->getClientOriginalExtension();
$fileName = uniqid().'.'.$extension;
Input::file('image')->move($destinationPath, $fileName);
}
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'image' => $fileName,
'password' => bcrypt($data['password']),
]);
}
When I try it the image upload correctly to the right folder but when I use thinker to see if the picture name is in the DB. There's nothing :
$user = App\User::OrderBy('id', 'desc')->first(); => App\User {#689 id: 5, name: "John Doe", email: "john.doe@gmail.com", image: "", created_at: "2015-12-03 11:48:12", updated_at: "2015-12-03 11:48:12", }
I tried many times and I can't understand why the picture name wont insert in the DB. I tried to replace the $fileName in the return user creation by "test" but nothing also. Is it the right method called when the registration is called ?
I would think so since the new update in laravel RegistersUsers.php page's postRegister method call the create method I used :
public function postRegister(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
Auth::login($this->create($request->all()));
return redirect($this->redirectPath());
}
Thanks in advance for your help !
Please or to participate in this conversation.