Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jemacimuro's avatar

Illuminate\Database\Eloquent\MassAssignmentException

I'm getting this exception... Can someone help?

Illuminate\Database\Eloquent\MassAssignmentException Add [hair] to fillable property to allow mass assignment on [App\Barbie].

here is my code:

Barbie::create([
    'hair' => 'Blond',
    'skin' => 'Brown'
]);
0 likes
2 replies
bobbybouwmann's avatar
Level 88

This means you need to make sure the model accepts the fields! You can two options here!

You can use guarded to white fields that you can't assign by default

class Barbie extends Model
{
    protected $guarded = []; // Accept all fields
}

Or you can whitelist fields that are fillable

class Barbie extends Model
{
    protected $fillable = ['hair', 'skin']; // Accept specific fields
}

Here is a good blog to help you out: https://medium.com/@kshitij206/laravel-mass-assignment-guarded-or-fillable-7c3a64b49ca6

jemacimuro's avatar

Thanks for the quick help The blog is also very useful

Please or to participate in this conversation.