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

[5.6] Extract setting mutated attribute into method #24307

merged 1 commit into from May 25, 2018


None yet
2 participants

mnabialek commented May 24, 2018

When dealing with accessors, code looks like now like this:

if ($this->hasGetMutator($key)) {
    return $this->mutateAttribute($key, $value);

so in case of custom method functionality, it's possible to override both hasGetMutator and mutateAttribute for custom code.

But for mutator code looked so far like this:

if ($this->hasSetMutator($key)) {
    $method = 'set'.Str::studly($key).'Attribute';

    return $this->{$method}($value);

so it's impossible to do similar change for mutator. In fact you need to override the whole setAttribute method just to make similar change because setting mutated attribute is not extracted to external method.

After this PR code for mutator condition would look like this:

if ($this->hasSetMutator($key)) {
    return $this->setMutatedAttributeValue($key, $value);

so now it would be enough just to override those 2 methods instead of touching setAttribute code. Also code is more consistent now I believe.

@taylorotwell taylorotwell merged commit 5837438 into laravel:5.6 May 25, 2018

2 checks passed

continuous-integration/styleci/pr The analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment