Eloquent Laravel 8 Laravel 9 Laravel 10 Laravel 11 Laravel 12

Mass Assignment Exception in Laravel - Fix

This error occurs when trying to mass assign attributes that aren't in the model's $fillable array.

The Error

Error Message
MassAssignmentException - Add [field] to fillable property

Common Causes

  1. 1 Field not listed in $fillable array
  2. 2 Using create() or update() with unguarded fields
  3. 3 $guarded array blocking the field

Solutions

1

Add field to $fillable array

PHP
class Post extends Model
{
    protected $fillable = [
        'title',
        'body',
        'author_id',
    ];
}
2

Use $guarded instead for fewer restrictions

PHP
class Post extends Model
{
    protected $guarded = ['id'];
}
3

Set attributes individually if needed

PHP
$post = new Post();
$post->title = $request->title;
$post->body = $request->body;
$post->save();

Need Help With Your Laravel Project?

I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.

Hafiz Riaz

About Hafiz

Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.

Get in touch →

Related Errors