Search code examples
laravellaravel-5laravel-artisanlaravel-5.5laravel-migrations

Receiving [Illuminate\Database\Eloquent\MassAssignmentException] email using Laravel 5.5


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.


Solution

  • 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.