Bosnadev\Repositories\Eloquent\Repository::findWhere PHP Method

findWhere() public method

Find a collection of models by the given query conditions.
public findWhere ( array $where, array $columns = ['*'], boolean $or = false ) : Illuminate\Database\Eloquent\Collection | null
$where array
$columns array
$or boolean
return Illuminate\Database\Eloquent\Collection | null
    public function findWhere($where, $columns = ['*'], $or = false)
    {
        $this->applyCriteria();
        $model = $this->model;
        foreach ($where as $field => $value) {
            if ($value instanceof \Closure) {
                $model = !$or ? $model->where($value) : $model->orWhere($value);
            } elseif (is_array($value)) {
                if (count($value) === 3) {
                    list($field, $operator, $search) = $value;
                    $model = !$or ? $model->where($field, $operator, $search) : $model->orWhere($field, $operator, $search);
                } elseif (count($value) === 2) {
                    list($field, $search) = $value;
                    $model = !$or ? $model->where($field, '=', $search) : $model->orWhere($field, '=', $search);
                }
            } else {
                $model = !$or ? $model->where($field, '=', $value) : $model->orWhere($field, '=', $value);
            }
        }
        return $model->get($columns);
    }