-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Hello, I recently updated my Laravel project from version 8 to Laravel 11.
I had some issues trying to add dynamic properties, as when I do this, they are treated as metaproperties. For example:
$user = new User();
$user['test'] = 'test';
If the property $hideMeta = false; is set on the model, dynamically added properties are not displayed, in my case, when returning a JSON response.
The current solution to this issue is to add the property $disableFluentMeta = true; in the models that uses the Metable trait.
However, this prevents distinguishing between properties that should be added as meta and those that should be added dynamically.
Proposed Solution
I suggest adding a parameter to the setAttribute function of the Metable trait to specify whether the added property should be treated as meta or not.
public function setAttribute($key, $value, $disableFluent = false) {
// Don't set meta data if fluent access is disabled.
if ((property_exists($this, 'disableFluentMeta') && $this->disableFluentMeta) || $disableFluent) {
return parent::setAttribute($key, $value);
}
// ... rest of the code
}
With this change, we can explicitly define whether a property should be meta or not when setting it
$user = new User();
$user->setAttribute('test', 'test', false);
This would provide better control over how attributes are handled.
Would it be possible to implement this improvement?
Thanks!