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
MassAssignmentException - Add [field] to fillable property
Common Causes
- 1 Field not listed in $fillable array
- 2 Using create() or update() with unguarded fields
- 3 $guarded array blocking the field
Solutions
Add field to $fillable array
class Post extends Model
{
protected $fillable = [
'title',
'body',
'author_id',
];
}
Use $guarded instead for fewer restrictions
class Post extends Model
{
protected $guarded = ['id'];
}
Set attributes individually if needed
$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.
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
Column Cannot Be Null Error in Laravel - Fix
SQLSTATE[23000]: Integrity constraint vi...
ValidationException in Laravel - Handling Validation Errors
The given data was invalid - ValidationE...
Model Not Found Exception in Laravel - Solutions
ModelNotFoundException - No query result...