skip to Main Content

I want to check:

$collection->whereNotNull('some_col')->orWhereNotNull('some_other_col')->get();

with Query Builder, orWhereNotNull exists, but not with Collections.
How can I then have the same functionality as orWhereNotNull with a collection? (whereNotNull does work with collections)

2

Answers


  1. You can use filter with a closure:

    $collection->filter(
        fn ($item) => null !== $item['some_col'] || null !== $item['some_other_col']
    );
    
    Login or Signup to reply.
  2. You can’t use ->get() becasue you don’t query a DB

    $collection->whereNotNull('some_col')->orWhereNotNull('some_other_col')
    

    will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search