0

Started a new Laravel 5.2 project and implemented the default authentication that comes with it. I wanted to modify it so that the registration form has a field for first name and last name instead of just 'name'. I added the fields in the view, the verification, and the model. When I test I get the following:enter image description here

Line 71 is in the following code block for last name or 'lname'.

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

When I add a dd on the data array right before the return/create like this:

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

I get this: enter image description here

We can clearly see that lname is, in fact, present in that array and should not be an undefined index. What's going on?

lola_the_coding_girl
  • 843
  • 2
  • 10
  • 22

1 Answers1

5

change this

'lname' => $data['lname '],

to this

'lname' => $data['lname'], # additional space within the key

In the error check line two, you can see 'lname '

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85