Skip to content

Conversation

@staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Sep 10, 2024

When using load() etc. with a callable, it receives a relationship instance, not an Eloquent builder (unlike whereHas()):

$users = User::all()->load([ 'posts' => fn (Relation $query) => $query->latest(), ]);

We can't use TModel here because it doesn't necessarily match any of Relation's template types.

Side note: PhpStorm's PHPDoc parser doesn't yet support asterisks inside a @param type and shows a warning. I'll check if there's already a bug report for this issue.

Thanks for discussing this topic @calebdw.

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

Labels

None yet

2 participants