Skip to content

Instantly share code, notes, and snippets.

@M-Abdullahi
Forked from sander3/mp-1-g3.md
Created December 8, 2020 09:13
Show Gist options
  • Save M-Abdullahi/8514eee3dd9507cd3806249a7bc2bb6d to your computer and use it in GitHub Desktop.
Save M-Abdullahi/8514eee3dd9507cd3806249a7bc2bb6d to your computer and use it in GitHub Desktop.
Medium post 1, Gist 3
$teams = App\Team::whereHas('portfolios', function ($query) use ($user) {
    // Only include teams with portfolios where...
    $query->whereHas('wallets', function ($query) use ($user) {
        // ...there are wallets...
        $query->whereHas('transactions', function ($query) {
            // ...with pending transactions...
            $query->whereStatus('pending');
        });

        // ...to be received by the given user.
        $query->where('walletable_id', $user->id);
        $query->where('walletable_type', App\User::class);
    });
})->with([
    ...
])->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment