petritr
2 months ago

Filter Model entry laravel collection

Posted 2 months ago by petritr

I need to go though each entry where some condition it meet.

I have all conditions in an extra array, the array can have more or few keys:

 array:2 [
  "date" => "true"
  "column" => 1
....
]

I would need to filter all Model entry's where implementation_date is not null and column is 1

$allUsers = Users::all();
        foreach ( array_keys($arrayColumns) as $key ) {
            if ($key === 'column' || $key === 'Two' || $key === 'Three') {
        $allUsers->where($key, 1)
        }
            if ($key === 'date' || $key === 'dateTwo' ) {
        $allUsers->where($key, '!=',null)
        }
    }

$allUsers->all();

I would like to habe something like the above but its not really working the where

Please sign in or create an account to participate in this conversation.