1

I've used a migration to update my users table to include a username filed, but on signup the field isn't populated in the database:

    $input = Input::only(['name', 'username', 'email', 'password']);
    $input['password'] = Hash::make($input['password']);
    User::create($input);
    return Redirect::to('login');

A dump of the post provides this:

array (size=4)
  'name' => string 'Joe Bloggs' (length=13)
  'username' => string 'jbloggs' (length=12)
  'email' => string '[email protected]' (length=24)
  'password' => string '$2y$10$whgTTwa5g.du/WJfJGhGtO******SYTerzL4bhOuedW4C' (length=60)

However the username field is always blank. No errors or warnings. I've tried a rollback and re-migrating, but there is no change.

Am I missing something? Thanks!

2
  • 1
    Do you have username in your fillable array? Commented Jan 2, 2015 at 9:37
  • @lukasgeiter Life saver! I've spent about 2 hours on this! Thanks a lot! Commented Jan 2, 2015 at 9:38

2 Answers 2

1

All attributes you pass to create need to be defined in the $fillable array so you can use them for mass assignment

In your case:

protected $fillable = array('name', 'username', 'email', 'password');

Alternatively you could also define the opposite, a set of guarded attributes:

protected $guarded = array('foo', 'bar');
Sign up to request clarification or add additional context in comments.

Comments

1

When you add a user in eloquent model you have an array $fillable which allows you to mass assign more can be found http://laravel.com/docs/4.2/eloquent#mass-assignment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.