1. Home
  2. Laravel
  3. Protected fields
#laravel#model

Protected method allows to set fillable or guarded fields in the model.

class Item extends Model {
    protected $fillable = [
        'title', 'content' // Only changes to these fields ARE allowed.
    ];
}

class OtherItem extends Model {
    protected $guarded = [
        'id', 'date' // Changes to these fields ARE NOT allowed.
    ];
}
copy
Full Laravel cheatsheet
Sitemap Git repository