Skip to content

[12.x] fix: Models having inconsistent guarding behaviour #56381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025

Conversation

JimTools
Copy link
Contributor

Fixing an issue with the Models having inconsistent guarding behaviour when $guarded is empty, but $fillable is populated, which causes a MassAssignmentException to be thrown. this happens because getGuarded in
GuardsAttributes has two different mechanisms for unguarding a model.

  1. $unguarded boolean property (default: false)
  2. $guarded array property (default: ['*'])

getGuarded() uses the $guarded and checks if it's false to return an empty array.

fillableFromArray() uses $unguarded and $fillable properties to test if the model is unguarded.

Both methods should use $unguarded for consistent behaviour.

closes #56380

JimTools added 3 commits July 22, 2025 19:38
Adding a unit test to cover edge cases where models exhibit inconsistent
behaviour when the $guard property is empty but the $fillable is not.
A MassAssignmentException is thrown. this happens because getGuarded in
GuardsAttributes has two different mechanisms for unguarding a model.

1. $unguarded boolean property (default: false)
2. $guarded array property (default: ['*'])

`getGuarded()` uses the $guarded and checks if it's false to return and
empty array.

`fillableFromArray()` uses $unguarded and $fillable properties to test if the model is unguarded.

Both methods should use $unguarded for consistent behaviour.
@JimTools JimTools force-pushed the bugfix/model-guard-with-fillable branch from 170ac1f to 2402d8e Compare July 22, 2025 20:28
@JimTools JimTools changed the title Bugfix/model guard with fillable [12.x] fix: Models having inconsistent guarding behaviour Jul 22, 2025
@taylorotwell taylorotwell merged commit d41f408 into laravel:12.x Jul 23, 2025
60 checks passed
@JimTools JimTools deleted the bugfix/model-guard-with-fillable branch July 25, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behaviour with Guarding Eloquent Models
2 participants