-
Notifications
You must be signed in to change notification settings - Fork 11.4k
protected $previous = []
in base Model
breaks Eloquent relationships named previous
when accessed from within the Model
#55828
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
Comments
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks!
This is only true for Unless you're doing something funky with Eloquent. a new protected property doesn't have any effect. But, we can confirm this we a reproduction repository. |
Thanks for the quick reply! Here’s a minimal reproduction that shows the issue clearly: Just to clarify: Even This behavior worked in 12.14.x and is broken in 12.15.0. It's not just a naming preference — it’s a silent behavioral change with real runtime consequences for apps relying on I don't think accessing relationships via magic accessor is funky at all. |
protected $previous = []
in base Model
breaks Eloquent relationships named previous
protected $previous = []
in base Model
breaks Eloquent relationships named previous
when accessed from within the Model via $this->previous
protected $previous = []
in base Model
breaks Eloquent relationships named previous
when accessed from within the Model via $this->previousprotected $previous = []
in base Model
breaks Eloquent relationships named previous
when accessed from within the Model
I honestly would say it shouldn't be hard to handle |
I have already fixed it for us, by using The maint point is still, that this is a potential breaking change, which was quite hard to debug, so it should not have found its way into a minor update. |
Uh oh!
There was an error while loading. Please reload this page.
Laravel Version
12.15.0
PHP Version
8.4.7
Database Driver & Version
MariaDB 11.7.2
Description
Version affected: Laravel
v12.15.0
Introduced by: #55729
After upgrading from Laravel 12.14.1 to 12.15.0, existing applications using an Eloquent relationship named
previous
are broken due to a new class property:This property was introduced in the
Model
class to "preserve" a relationship internally, but it shadows any existing Eloquent relationship using the nameprevious
.Impact
In PHP, class properties take precedence over
__get()
dynamic access, so:now always returns the
protected $previous
array, not the related model.This causes existing apps with a relationship like:
to suddenly break, returning
[]
instead of aTask
instance.Why This is a Breaking Change
previous
,next
,parent
, etc.null
or exception).Suggested Fix
At the very least there has to be warning about this problem. In my opinion it should never have been released as a minor update. I would vote for to actually revert and postpone this to a major version.
This incident highlights a larger structural limitation in Laravel's current Eloquent model system: attributes and class properties share the same namespace, and magic access provides no guardrails against collisions.
A longer-term fix could involve refactoring the
HasAttributes
trait to encapsulate model attributes in a dedicated container, clearly separating user-defined class properties from Eloquent-managed state. This would eliminate accidental shadowing and make models safer and more predictable at scale.References
Please consider reverting this change or implementing a safer alternative.
Steps To Reproduce
Create a model with a
previous()
relationship:Load and access the relation:
If you call the relation manually, it works:
Downgrade to Laravel 12.14.1 → works again as expected.
The text was updated successfully, but these errors were encountered: