app/Filters/BaseFilter.php
protected function buildSearch($query, $searchables, $value)
    {
        foreach ($searchables as $key => $searchable) {
            if (is_array($searchable)) {
                $query->orWhereHas($key, function (Builder $query) use($searchable, $value) {
                    $query->where(function (Builder $query) use($searchable, $value) {
                        $this->buildSearch($query, $searchable, $value);
                    });
                });
            } else {
                if ($query->getConnection()->getDriverName() == 'pgsql')
                    $query->orWhere($query->qualifyColumn($searchable), 'ilike', '%'.str_replace(' ', '%', $value).'%');
                else
                    $query->orWhere($query->qualifyColumn($searchable), 'like', '%'.str_replace(' ', '%', $value).'%');
            }
        }
    }
protected function buildSearch($query, $searchables, $value)
    {
        foreach ($searchables as $key => $searchable) {
            if (is_array($searchable)) {
                $query->orWhereHas($key, function (Builder $query) use($searchable, $value) {
                    $query->where(function (Builder $query) use($searchable, $value) {
                        $this->buildSearch($query, $searchable, $value);
                    });
                });
            } else {
                if ($query->getConnection()->getDriverName() == 'pgsql')
                    $query->orWhere($query->qualifyColumn($searchable), 'ilike', '%'.str_replace(' ', '%', $value).'%');
                else
                    $query->orWhere($query->qualifyColumn($searchable), 'like', '%'.str_replace(' ', '%', $value).'%');
            }
        }
    }
protected function buildSearch ( $ query , $ searchables , $ value ) { foreach ( $ searchables as $ key => $ searchable ) { if ( is_array ( $ searchable ) ) { $ query -> orWhereHas ( $ key , function ( Builder $ query ) use ( $ searchable , $ value ) { $ query -> where ( function ( Builder $ query ) use ( $ searchable , $ value ) { $ this -> buildSearch ( $ query , $ searchable , $ value ) ; } ) ; } ) ; } else { if ( $ query -> getConnection ( ) -> getDriverName ( ) == 'pgsql' ) $ query -> orWhere ( $ query -> qualifyColumn ( $ searchable ) , 'ilike' , '%' . str_replace ( ' ' , '%' , $ value ) . '%' ) ; else $ query -> orWhere ( $ query -> qualifyColumn ( $ searchable ) , 'like' , '%' . str_replace ( ' ' , '%' , $ value ) . '%' ) ; } } }
Recursive Build Search
@param  \Illuminate\Database\Eloquent\Builder $query
@param  array|string $searchables
@param  string $value
Recursive Build Search