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 2 commits into from Jan 6, 2019


None yet
2 participants
Copy link

staudenmeir commented Jan 6, 2019

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed

@staudenmeir staudenmeir deleted the staudenmeir:load-morph branch Jan 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment