Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Eloquent: Mass Assignment Protection

Protect your models from mass assignment vulnerabilities.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Fillable Array
  2. Guarded Array
  3. Guard All
  4. Force Fill
  5. Unguard Temporarily

Secure mass assignment:

Fillable Array

php
protected $fillable = ['name', 'email', 'password'];

Guarded Array

php
protected $guarded = ['id', 'is_admin'];

Guard All

php
protected $guarded = ['*'];

Force Fill

php
$user->forceFill([
    'is_admin' => true,
])->save();

Unguard Temporarily

php
Model::unguard();
User::create($data);
Model::reguard();
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read