vendor/yajra/laravel-datatables-oracle/src/Engines/QueryBuilderEngine.php
/**
     * Add relation query on global search.
     *
     * @param mixed $query
     * @param string $relation
     * @param string $column
     * @param string $keyword
     */
Add relation query on global search.
Add relation query on global search .
protected function compileRelationSearch($query, $relation, $column, $keyword)
    {
        $myQuery = clone $this->query;
        $relationChunk = [];
        $lastQuery = $query;
        $relations    = explode('.', $relation);
        $lastRelation = end($relations);
        foreach ($relations as $relation) {
            $relationType = $myQuery->getModel()->{$relation}();
            $myQuery->orWhereHas($relation, function ($builder) use (
                $column,
                $keyword,
                $query,
                $relationType,
                $relation,
                $lastRelation,
                &$relationChunk,
                &$lastQuery
            ) {
                $builder->select($this->connection->raw('count(1)'));
                if ($relation == $lastRelation) {
                    $this->compileQuerySearch($builder, $column, $keyword, '');
                }
                $relationChunk[$relation] = [
                    'builder'      => $builder,
                    'relationType' => $relationType,
                    'query'        => $lastQuery,
                ];
                $lastQuery = $builder;
            });
            $myQuery = $relationType;
        }
        $relationChunk = array_reverse($relationChunk, true);
        end($relationChunk);
        $lastRelation = key($relationChunk);
        reset($relationChunk);
        foreach ($relationChunk as $relation => $chunk) {
            $builder  = $chunk['builder'];
            $query    = $chunk['query'];
            $bindings = $builder->getBindings();
            $builder  = "({$builder->toSql()}) >= 1";
            if ($lastRelation == $relation) {
                $relationMethod = "orWhereRaw";
            } else {
                $relationMethod = "whereRaw";
            }
            $query->{$relationMethod}($builder, $bindings);
        }
    }
protected function compileRelationSearch ( $ query , $ relation , $ column , $ keyword ) { $ myQuery = clone $ this -> query ; $ relationChunk = [ ] ; $ lastQuery = $ query ; $ relations = explode ( '.' , $ relation ) ; $ lastRelation = end ( $ relations ) ; foreach ( $ relations as $ relation ) { $ relationType = $ myQuery -> getModel ( ) -> { $ relation } ( ) ; $ myQuery -> orWhereHas ( $ relation , function ( $ builder ) use ( $ column , $ keyword , $ query , $ relationType , $ relation , $ lastRelation , & $ relationChunk , & $ lastQuery ) { $ builder -> select ( $ this -> connection -> raw ( 'count(1)' ) ) ; if ( $ relation == $ lastRelation ) { $ this -> compileQuerySearch ( $ builder , $ column , $ keyword , '' ) ; } $ relationChunk [ $ relation ] = [ 'builder' => $ builder , 'relationType' => $ relationType , 'query' => $ lastQuery , ] ; $ lastQuery = $ builder ; } ) ; $ myQuery = $ relationType ; } $ relationChunk = array_reverse ( $ relationChunk , true ) ; end ( $ relationChunk ) ; $ lastRelation = key ( $ relationChunk ) ; reset ( $ relationChunk ) ; foreach ( $ relationChunk as $ relation => $ chunk ) { $ builder = $ chunk [ 'builder' ] ; $ query = $ chunk [ 'query' ] ; $ bindings = $ builder -> getBindings ( ) ; $ builder = " ( { $ builder -> toSql ( ) } ) >= 1 " ; if ( $ lastRelation == $ relation ) { $ relationMethod = " orWhereRaw " ; } else { $ relationMethod = " whereRaw " ; } $ query -> { $ relationMethod } ( $ builder , $ bindings ) ; } }
Add relation query on global search.
Add relation query on global search .
/**
         * For compile nested relation, we need store all nested relation as array
         * and reverse order to apply where query.
         * With this method we can create nested sub query with properly relation.
         */ /**
         * Store all relation data that require in next step
         */ /**
         * Store last eloquent query builder for get next relation.
         */ // We will perform search on last relation only. // Put require object to next step!! // This is trick make sub query. // This is trick to make nested relation by pass previous relation to be next query eloquent builder /**
         * Reverse them all
         */ /**
         * Create valuable for use in check last relation
         */ /**
         * Walking ...
         */ // Prepare variables // Check if it last relation we will use orWhereRaw // For case parent relation of nested relation. // We must use and for properly query and get correct result