-
Notifications
You must be signed in to change notification settings - Fork 321
Add support for Model accessors to be called #257
Conversation
@@ -162,6 +162,10 @@ public function getAttribute($key) | |||
return; | |||
} | |||
|
|||
if ($this->hasGetMutator($key)) { | |||
return $this->mutateAttribute($key, $this->getTranslation($locale)->$key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you call call $this->mutateAttribute()
instead of $this->getAttributeValue($key)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the reply, @dimsav .
$this->getAttributeValue($key)
will check the Model's $attribute
array. and does not get the value from the translation. then internally checks if the $key
has a mutator, then calls the mutator with the Model's $value
(which is not translated.).
So calling $this->getAttributeValue($key)
does not mutate translated attributes.
But, you are right, using the $this->getAttributeValue($key)
makes more sense, so I will change the code (by checking if $key
has a mutator, then push it to $attributes
before calling $this->getAttributeValue($key)
.
Thanks a lot for this PR! Can you write a test that these changes will fix? |
I will write the test ASAP for this. |
…ation. Change the behavior to use Model::getAttributeValue() method. Add a test for mutating translated attribute Fixing schema rollback add missing namespace
Ok, the tests are passing. Do you want me to squash commits? Oh, and BTW, I've seen the tests are extremely slow, take a look at this branch which I tried to run the tests as in memory sqlite, and it is way faster than mysql. |
Thanks @easteregg! Indeed the tests are slow. From my experience running tests in sqlite is a bad practice because some mysql errors are not shown. |
The changes were just released. There are interesting techniques we could use to speedup mysql in tests. We can do this at a later moment. |
Thank you for your answer. I guess this issue is closed now. |
This fixes #256 .