public function search($filters = [])
    {
        // Set resolved
        $resolved = [];

        // Check the filters
        if (!isset($filters) || !is_array($filters)) {
            throw new \InvalidArgumentException('Undefined search filters', 400);
        }

        // Set limit, offset and order
        if (isset($filters['limit'])) {
            $this->limit($filters['limit']);
        }
        if (isset($filters['offset'])) {
            $this->offset($filters['offset']);
        }
        if (isset($filters['order'])) {
            $this->orderBy($filters['order']);
        }

        // Remove invalid filters
        $filters = array_intersect_key($filters, array_flip(array_keys($this->filters)));

        // Set where in conditions
        foreach ($filters as $key => $value) {

            // Get filter data
            $current = $this->filters[$key];
            $filterName = $current[0];

            // Add condition
            if (isset($this->relationships['belongsToMany']) && is_array($this->relationships['belongsToMany']) && count($this->relationships['belongsToMany'])) {
                foreach ($this->relationships['belongsToMany'] as $join) {
                    if ($filterName === $join['alias']) {
                        $this->whereIn($join['pivot'] . '.' . $join['foreignKey'], (array) $value, $join['pivot']);
                        $resolved[] = $key;
                    }
                }
            }
        }

        // Set where conditions
        foreach ($filters as $key => $value) {
            if (!in_array($key, $resolved)) {

                // Get filter data
                $current = $this->filters[$key];
                $column = $current[0];
                $operator = isset($current[1])? $current[1] : '=';
                if ($operator === 'LIKE') {
                    $value = '%' . $value . '%';
                }
                if ($operator === 'IS_NOT_EMPTY') {
                    $operator = '<>';
                    $value = '';
                }

                // Add condition
                $table = isset($current[2])? $current[2] : $this->table;
                $this->where($column, $value, $operator, $table);
            }
        }

        // Return model instance
        return $this;
    }
public function search($filters = [])
    {
        // Set resolved
        $resolved = [];

        // Check the filters
        if (!isset($filters) || !is_array($filters)) {
            throw new \InvalidArgumentException('Undefined search filters', 400);
        }

        // Set limit, offset and order
        if (isset($filters['limit'])) {
            $this->limit($filters['limit']);
        }
        if (isset($filters['offset'])) {
            $this->offset($filters['offset']);
        }
        if (isset($filters['order'])) {
            $this->orderBy($filters['order']);
        }

        // Remove invalid filters
        $filters = array_intersect_key($filters, array_flip(array_keys($this->filters)));

        // Set where in conditions
        foreach ($filters as $key => $value) {

            // Get filter data
            $current = $this->filters[$key];
            $filterName = $current[0];

            // Add condition
            if (isset($this->relationships['belongsToMany']) && is_array($this->relationships['belongsToMany']) && count($this->relationships['belongsToMany'])) {
                foreach ($this->relationships['belongsToMany'] as $join) {
                    if ($filterName === $join['alias']) {
                        $this->whereIn($join['pivot'] . '.' . $join['foreignKey'], (array) $value, $join['pivot']);
                        $resolved[] = $key;
                    }
                }
            }
        }

        // Set where conditions
        foreach ($filters as $key => $value) {
            if (!in_array($key, $resolved)) {

                // Get filter data
                $current = $this->filters[$key];
                $column = $current[0];
                $operator = isset($current[1])? $current[1] : '=';
                if ($operator === 'LIKE') {
                    $value = '%' . $value . '%';
                }
                if ($operator === 'IS_NOT_EMPTY') {
                    $operator = '<>';
                    $value = '';
                }

                // Add condition
                $table = isset($current[2])? $current[2] : $this->table;
                $this->where($column, $value, $operator, $table);
            }
        }

        // Return model instance
        return $this;
    }
public function search ( $ filters = [ ] ) { // Set resolved $ resolved = [ ] ; // Check the filters if ( ! isset ( $ filters ) || ! is_array ( $ filters ) ) { throw new \ InvalidArgumentException ( 'Undefined search filters' , 400 ) ; } // Set limit, offset and order if ( isset ( $ filters [ 'limit' ] ) ) { $ this -> limit ( $ filters [ 'limit' ] ) ; } if ( isset ( $ filters [ 'offset' ] ) ) { $ this -> offset ( $ filters [ 'offset' ] ) ; } if ( isset ( $ filters [ 'order' ] ) ) { $ this -> orderBy ( $ filters [ 'order' ] ) ; } // Remove invalid filters $ filters = array_intersect_key ( $ filters , array_flip ( array_keys ( $ this -> filters ) ) ) ; // Set where in conditions foreach ( $ filters as $ key => $ value ) { // Get filter data $ current = $ this -> filters [ $ key ] ; $ filterName = $ current [ 0 ] ; // Add condition if ( isset ( $ this -> relationships [ 'belongsToMany' ] ) && is_array ( $ this -> relationships [ 'belongsToMany' ] ) && count ( $ this -> relationships [ 'belongsToMany' ] ) ) { foreach ( $ this -> relationships [ 'belongsToMany' ] as $ join ) { if ( $ filterName === $ join [ 'alias' ] ) { $ this -> whereIn ( $ join [ 'pivot' ] . '.' . $ join [ 'foreignKey' ] , ( array ) $ value , $ join [ 'pivot' ] ) ; $ resolved [ ] = $ key ; } } } } // Set where conditions foreach ( $ filters as $ key => $ value ) { if ( ! in_array ( $ key , $ resolved ) ) { // Get filter data $ current = $ this -> filters [ $ key ] ; $ column = $ current [ 0 ] ; $ operator = isset ( $ current [ 1 ] ) ? $ current [ 1 ] : '=' ; if ( $ operator === 'LIKE' ) { $ value = '%' . $ value . '%' ; } if ( $ operator === 'IS_NOT_EMPTY' ) { $ operator = '<>' ; $ value = '' ; } // Add condition $ table = isset ( $ current [ 2 ] ) ? $ current [ 2 ] : $ this -> table ; $ this -> where ( $ column , $ value , $ operator , $ table ) ; } } // Return model instance return $ this ; }
Sets an array of filters as where conditions

@param array $params Search parameters
@return bool|array Array of results, or false
Sets an array of filters as where conditions