$teams = App\Team::with([
'portfolios' => function ($query) use ($user) {
// Only include portfolios where...
$query->whereHas('wallets', function ($query) use ($user) {
// ...there are wallets...
$query->whereHas('transactions', function ($query) {
// ...with pending transactions...
$query->whereStatus('pending');
});
$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');
});