Skip to content
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
merged 1 commit into from
May 25, 2018

Conversation

mnabialek
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants