Laravel用户::创建缺失数据

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 'jbloggs@gmail.com' (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!

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');

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