protected function newSearchQuery($searchQuery, array $searchableFields = null, $statementsType = null, array $options = array(), $modelClass = null)
    {
        // Query without scopes
        if (!is_string($modelClass)) {
            $modelClass = $this->modelClass;
        }
        $q = call_user_func(array(new $modelClass(), 'newQueryWithoutScopes'));

        if ($searchableFields === null || empty($searchableFields)) {
            $searchableFields = $instance->getVisible();
        }

        // If search query is a string
        if (is_string($searchQuery)) {
            $st = strtoupper($statementsType) === 'AND'
                ? 'where'
                : 'orWhere'
            ;

            foreach ($searchableFields as $field) {
                $q->{$st}($field, 'LIKE', "%{$searchQuery}%");
            }
        }
        // If search query is an array
        elseif (is_array($searchQuery)) {
            $st = strtoupper($statementsType) === 'OR'
                ? 'orWhere'
                : 'where'
            ;

            foreach ($searchableFields as $field) {
                if (isset($searchQuery[$field])) {
                    $q->{$st}($field, 'LIKE', "%{$searchQuery[$field]}%");
                }
            }
        } else {
            throw new \ErrorException(sprintf('%s::%s() expects parameter 1 to be string or array, %s given',
                __CLASS__,
                __METHOD__,
                gettype($searchQuery)
            ));
        }

        return $this->newCollectionQuery($options, $modelClass)
            ->addNestedWhereQuery($q->getQuery())
        ;
    }
protected function newSearchQuery($searchQuery, array $searchableFields = null, $statementsType = null, array $options = array(), $modelClass = null)
    {
        // Query without scopes
        if (!is_string($modelClass)) {
            $modelClass = $this->modelClass;
        }
        $q = call_user_func(array(new $modelClass(), 'newQueryWithoutScopes'));

        if ($searchableFields === null || empty($searchableFields)) {
            $searchableFields = $instance->getVisible();
        }

        // If search query is a string
        if (is_string($searchQuery)) {
            $st = strtoupper($statementsType) === 'AND'
                ? 'where'
                : 'orWhere'
            ;

            foreach ($searchableFields as $field) {
                $q->{$st}($field, 'LIKE', "%{$searchQuery}%");
            }
        }
        // If search query is an array
        elseif (is_array($searchQuery)) {
            $st = strtoupper($statementsType) === 'OR'
                ? 'orWhere'
                : 'where'
            ;

            foreach ($searchableFields as $field) {
                if (isset($searchQuery[$field])) {
                    $q->{$st}($field, 'LIKE', "%{$searchQuery[$field]}%");
                }
            }
        } else {
            throw new \ErrorException(sprintf('%s::%s() expects parameter 1 to be string or array, %s given',
                __CLASS__,
                __METHOD__,
                gettype($searchQuery)
            ));
        }

        return $this->newCollectionQuery($options, $modelClass)
            ->addNestedWhereQuery($q->getQuery())
        ;
    }
protected function newSearchQuery ( $ searchQuery , array $ searchableFields = null , $ statementsType = null , array $ options = array ( ) , $ modelClass = null ) { // Query without scopes if ( ! is_string ( $ modelClass ) ) { $ modelClass = $ this -> modelClass ; } $ q = call_user_func ( array ( new $ modelClass ( ) , 'newQueryWithoutScopes' ) ) ; if ( $ searchableFields === null || empty ( $ searchableFields ) ) { $ searchableFields = $ instance -> getVisible ( ) ; } // If search query is a string if ( is_string ( $ searchQuery ) ) { $ st = strtoupper ( $ statementsType ) === 'AND' ? 'where' : 'orWhere' ; foreach ( $ searchableFields as $ field ) { $ q -> { $ st } ( $ field , 'LIKE' , "%{$searchQuery}%" ) ; } } // If search query is an array elseif ( is_array ( $ searchQuery ) ) { $ st = strtoupper ( $ statementsType ) === 'OR' ? 'orWhere' : 'where' ; foreach ( $ searchableFields as $ field ) { if ( isset ( $ searchQuery [ $ field ] ) ) { $ q -> { $ st } ( $ field , 'LIKE' , "%{$searchQuery[$field]}%" ) ; } } } else { throw new \ ErrorException ( sprintf ( '%s::%s() expects parameter 1 to be string or array, %s given' , __CLASS__ , __METHOD__ , gettype ( $ searchQuery ) ) ) ; } return $ this -> newCollectionQuery ( $ options , $ modelClass ) -> addNestedWhereQuery ( $ q -> getQuery ( ) ) ; }
Get new search query instance.

@param string|array $searchQuery      The search query
@param array        $searchableFields The searchable fields (default: all visible fields in the model)
@param string|null  $statmentsType
@param array        $options          The query options
@param string|null  $modelClass

@return \Illuminate\Database\Eloquent\Builder

@throws \Subbly\Api\Service\Exception
Get new search query instance .