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

beCoder's avatar

Why showing this exception? Illuminate \ Database \ Eloquent \ MassAssignmentException

Hi,

i'm persisting data into post table but getting this error:

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

here is my code:

Post::create([
    'title' => 'Post Title',
    'description' => 'Post Description'
]);

any solution?

0 likes
1 reply
ahsan's avatar
ahsan
Best Answer
Level 46

this is MassAssignmentException

you need to add this in your model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
}
4 likes

Please or to participate in this conversation.