Getting an empty collection in Laravel

252 Views Asked by At

I'm trying to create an automatic email that will send an email to a user if they have any products waiting on them to approve for use. I'm having an issue when I run my artisan command; I'm still getting empty collections instead of only products that need approval.

$users = User::all();
foreach ($users as $user) {
    $outstandingProducts = Product::outstandingProducts($user);
    if (empty($outstandingProducts)) continue;
    dd($outstandingProducts);
}

Product model

public static function outstandingProducts(User $user)
{
    return Product::where('approver_id', $user->id)
        ->where('status', 'Pending Approval')->get();
}  
0

There are 0 best solutions below