Add "default" attribute value in Attribute class #50436
Unanswered
antonkomarev
asked this question in
Ideas
Replies: 1 comment 3 replies
-
This proposal is better, you already started some implementation? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now there is ability to specify how to
get
andset
attribute using theIlluminate\Database\Eloquent\Casts\Attribute
class:To specify default value we should define it in the
$attributes
class property array. You could see how it works right now in Laravel Love package.I propose to add one more optional parameter
default
to the Attribute class:Then we will cover all class attribute use cases in one place, make them explicit and allow to dynamically decide what value should be default.
I've tried to add fallback value to
get
as$value ?? self::RATE_DEFAULT
, but it's not working for all cases.I found similar proposal, but proposed implementation is different:
One more thing to consider: maybe there is one more improvement to call default from the
get
andset
methods to not duplicate resolving default value logic.Beta Was this translation helpful? Give feedback.
All reactions