Ejemplo n.º 1
0
 /**
  * @param WithJoinEloquentBuilder $originalQuery
  * @param $search
  * @internal param $query
  */
 protected function addSearchToQuery(WithJoinEloquentBuilder $originalQuery, $search)
 {
     $originalQuery->getQuery()->whereNested(function (Builder $query) use($search, $originalQuery) {
         $table = $this->instance->getTable();
         $columns = $this->getColumns($table);
         foreach ($columns as $column => $type) {
             $field = implode('.', [$table, $column]);
             if ($this->isDateColumn($type)) {
                 $field = DB::raw('convert(' . $field . ' using utf8)');
             }
             $query->orWhere($field, 'like', $search);
         }
         /** @var ColumnInterface[] $displayColumns */
         $displayColumns = $this->modelItem->getColumns();
         foreach ($displayColumns as $column) {
             $name = $column->getName();
             if (strpos($name, '.') !== false && $this->inWith($name, $originalQuery) && $this->modelItem->isWithJoinEnabled()) {
                 $query->orWhere($name, 'like', $search);
             }
         }
     });
 }