1. Home
  2. Laravel
  3. Protected fields

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

#laravel#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
NordVPN NordVPN