0

Am following a tutorial attempting to learn how to use Laravel5.5. After following a step which said to add protected $fillable = array('email', 'password', 'name'); to the User model.

Which I'm assuming is setting which fields are mass assignable fields? The next step was to add:

User::create(array(
    'email' => 'your@email.com',
    'password' => Hash::make('password'),
    'name' => 'John Doe'
));

Which I'm to understand is to add said user to the db.

When I run php artisan migrate I receive [Illuminate\Database\Eloquent\MassAssignmentException] email and I have no idea why. I have tried adding Eloquent::unguard(), have tried to make it all guardable.

Have removed email from the fillable array. Have got rid of email altogther.

Each time I run php artisan migrate the error is this same.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Rue
  • 49
  • 1
  • 10

1 Answers1

1

It should work without any problems based on your description.

So make sure:

  • you are using valid User model (maybe you have 2 and you set fillable only in one of them)?
  • you are not inserting other data in migrations. It's quite possible the problem is for other model and not for User model.
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I've checked User models and there seems to be one which is empty and one which I created. The other migrations are inserting data but not for an `email` field. It seems as though the tutorial I'm following might be based on Laravel 4 so I may need to stop and find one based on 5.5. – Rue Nov 26 '17 at 13:01
  • Idea about fillable and MassAssignment wasn't change so for sure there is wrong something else – Marcin Nabiałek Nov 26 '17 at 13:56
  • It was issues with trying to add fake users via the migration. – Rue Nov 27 '17 at 15:11