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.7] Improve loadMorph() #27081

Merged
merged 2 commits into from
Jan 6, 2019
Merged

[5.7] Improve loadMorph() #27081

merged 2 commits into from
Jan 6, 2019

Conversation

staudenmeir
Copy link
Contributor

loadMorph() has the same issue that #22363 fixed for load():

class Post extends Model {
    protected $with = ['user'];
}

$comments = Comment::with('commentable')->get()
    ->loadMorph('commentable', [
        Post::class => 'tags',
    ]);

When loadMorph() loads the tags relationship, it also loads the user relationship from $with.

We can fix it by just calling load() – which is also shorter.

We can also replace the filter() clause with a null coalescing operator.

@taylorotwell taylorotwell merged commit 0e9b877 into laravel:5.7 Jan 6, 2019
@staudenmeir staudenmeir deleted the load-morph branch January 6, 2019 21:44
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