Laravel

Laravel Eloquent: Mass Assignment Protection

January 16, 2026 1 min read 22 views

Secure mass assignment:

Fillable Array

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

Guarded Array

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

Guard All

protected $guarded = ['*'];

Force Fill

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

Unguard Temporarily

Model::unguard();
User::create($data);
Model::reguard();
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!