Fix : Add [_token] to fillable property to allow mass assignment Laravel

If you are working with Laravel and you encounter the following error while creating a new record in the database using Laravel Models

Add [_token] to fillable property to allow mass assignment on [App\Models\Post].

A mass assignment exception is usually caused because you didn’t specify the fillable (or guarded the opposite) attributes in your model. Do this:

class Post extends Eloquent {
    protected $fillable = ['field1', 'foo', 'bar'];
}

This way you also don’t have to worry about _token because only the specified fields will be filled and saved in the db no matter what other stuff you pass to the model.

Related Articles

Site Footer