Skip to content

[12.x] Add support for nested array notation within loadMissing #56711

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

Open
wants to merge 2 commits into
base: 12.x
Choose a base branch
from

Conversation

angus-mcritchie
Copy link

This pull request attempts to solve the same issue as this PR #54554 but was closed after @taylorotwell , the legend himself, said in this comment #54554 (comment)

Could we not re-use the logic we use for this elsewhere? It feels odd to have to recreate this logic here.

So this PR attempts to do just that.

As a refresher, this PR aims to make loadMissing consistent with load and with Eloquent methods, as I'm sure I'm not the only developer who has tried the following code and found out the hard way it doesn't work as expected.

$posts->loadMissing([
    'comments' => [
        'user' => fn($query) => $query->select(['id', 'name']),
        'relatedComments'
    ],
    'relatedPosts'
]);

Credit to @lioneaglesolutions for some of the tests 👍

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.

1 participant