Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t0berius's avatar

whereNotNull() on collection

Since collections don't support "whereNotNull()", what's the best way to do something like:

public function getTotalInvestedAmountAttribute()
{
    return $this->deposits->whereNotNull('txid')->sum('amount');
}

The whereNotNull() statement cannot be used, because it's a collection.

0 likes
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

What if you try this-

    return $this->deposits->where('txid', '!=', NULL)->sum('amount');
9 likes

Please or to participate in this conversation.