newQuery() public method

Get a new query builder for the model's table.
public newQuery ( ) : Builder
return Builder
 /**
  * Set the constraints for an eager load of the relation.
  *
  * @param  array $models
  *
  * @return void
  */
 public function addEagerConstraints(array $models)
 {
     $this->query->whereNested(function (Builder $inner) use($models) {
         // We will use this query in order to apply constraints to the
         // base query builder
         $outer = $this->parent->newQuery();
         foreach ($models as $model) {
             $outer->setQuery($inner)->orWhereDescendantOf($model);
         }
     });
 }
Example #2
0
 /**
  * Make a new instance of the entity to query on.
  *
  * @param \Illuminate\Database\Eloquent\Builder $with
  */
 public function make(array $with = [])
 {
     if (method_exists($this->model, 'translations')) {
         if (!in_array('translations', $with)) {
             $with[] = 'translations';
         }
     }
     return $this->model->newQuery()->with($with);
 }
Example #3
0
 /**
  * @return Builder
  */
 public function newQuery()
 {
     if (is_string($this->modelClass)) {
         return (new $this->modelClass())->newQuery();
     }
     if ($this->modelClass instanceof Model) {
         return $this->modelClass->newQuery();
     }
     return $this->modelClass;
 }
Example #4
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $grid = new Grid((new GridConfig())->setDataProvider(new EloquentDataProvider($this->userModel->newQuery()))->setColumns([(new FieldConfig('name', 'Логин'))->setCallback(function ($value, $vl) {
         return link_to_route('admin.user.edit', $value, $vl->getSrc());
     })->setSortable(true)->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_LIKE)), (new FieldConfig('email'))->setSortable(true)->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_EQ)), (new FieldConfig('created_at', 'Дата создания'))->setSortable(true)->setCallback(function (\Carbon\Carbon $value) {
         return $value->toDateString();
     })->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_LIKE)), (new FieldConfig('roles', 'Роли'))->setCallback(function ($value) {
         $list = $value->lists('display_name');
         if (version_compare(app()->version(), '5.1.0', '>=')) {
             $list = $list->all();
         }
         return implode(', ', $list);
     })]));
     return view('adminPanel::user.index', compact('grid'));
 }
Example #5
0
 public function __construct(Model $model)
 {
     $this->model = $model;
     $this->query = $model->newQuery();
     $this->parser = new DefaultParser();
     $this->introspector = new EloquentPathIntrospector($this->parser);
 }
Example #6
0
 public function newQuery()
 {
     $query = parent::newQuery();
     if ($this->includes) {
         return $query->with($this->includes);
     }
     return $query;
 }
Example #7
0
 public function newQuery($ordered = true)
 {
     $query = parent::newQuery();
     if (empty($ordered)) {
         return $query;
     }
     return $query->orderBy('weight', 'ASC');
 }
 /**
  * Get a new query builder for the model.
  * set any type of scope you want on this builder in a child class, and it'll
  * keep applying the scope on any read-queries on this model
  *
  * @return Reposed\Builder
  */
 public function newQuery($excludeDeleted = true)
 {
     $builder = parent::newQuery($excludeDeleted);
     if ($this->isSubType()) {
         $builder->where($this->typeField, $this->getClass($this->typeField));
     }
     return $builder;
 }
Example #9
0
 /**
  * @return $this|\Illuminate\Database\Eloquent\Builder
  */
 public function newQuery()
 {
     $query = parent::newQuery();
     if (substr(\Request::path(), 0, 6) !== 'admin/') {
         return $query->where('is_active', 1);
     }
     return $query;
 }
Example #10
0
 public function newQuery($excludeDeleted = true)
 {
     $raw = '';
     foreach ($this->geofields as $column) {
         $raw .= ' astext(' . $column . ') as ' . $column . ' ';
     }
     return parent::newQuery($excludeDeleted)->addSelect('*', DB::raw($raw));
 }
Example #11
0
 /**
  * Apply order and search filters.
  *
  * @return Datagrid
  * @throws \Exception
  */
 public function applyFilters()
 {
     $this->validate();
     $query = $this->searchInEveryColumn($this->model->newQuery());
     $query->orderBy($this->orderBy['column'], $this->orderBy['type']);
     $this->itens = $query->paginate($this->paginate);
     return $this;
 }
 /**
  * @param JsonApiRequest $request
  * @return Paginator|Collection|Model|Response|null
  */
 protected function search(JsonApiRequest $request)
 {
     if (!$this->search) {
         return $this->notImplemented();
     }
     $builder = $this->model->newQuery();
     return $this->search->search($builder, $request->getParameters());
 }
 public function newQuery($excludeDeleted = true)
 {
     $builder = parent::newQuery($excludeDeleted);
     if (get_class($this) !== $this->getStiBaseClass()) {
         $builder->where($this->getStiClassField(), '=', get_class($this));
     }
     return $builder;
 }
Example #14
0
    /**
     * Redefined for STI pattern
     *
     * @return mixed
     */
    public function newQuery() {
        $builder = parent::newQuery();

        if ($this->sti_field) {
            $builder->where($this->sti_field, get_class($this));
        }

        return $builder;
    }
Example #15
0
 public function newQuery($excludeDeleted = true)
 {
     $class = get_called_class();
     $query = parent::newQuery($excludeDeleted);
     if ($class != 'App\\Post') {
         $query->where($this->table . '.model', '=', $class);
     }
     return $query;
 }
Example #16
0
 public function newQuery()
 {
     $builder = parent::newQuery();
     if (!Acl::isGuard()) {
         return $builder;
     }
     $ok = $this->applyPermissionsRules($builder);
     return $ok !== false ? $builder : $builder->whereRaw('1 = 0');
 }
Example #17
0
 public function newQuery()
 {
     $query = parent::newQuery();
     if (Auth::guest()) {
         return $query;
     }
     //se a pessoa não estiver logada, nada é alterado aki...
     return $query->where('idUsuario', '=', Auth::user()->id);
 }
Example #18
0
 /**
  * @inheritdoc
  */
 public function query($criteria = [], $with = [], Context $context = null)
 {
     $query = $this->model->newQuery();
     if ($criteria instanceof CriteriaContract) {
         $criteria->apply($query, $this);
     } elseif (!empty($criteria)) {
         $query->where($criteria);
     }
     if ($context !== null && ($contextFields = $context->getContextFields()) && !empty($contextFields)) {
         $fields = $this->fields();
         foreach ($contextFields as $field => $value) {
             if (!in_array($field, $fields)) {
                 unset($contextFields[$field]);
             }
         }
         $query->where($contextFields);
     }
     return $query;
 }
 /**
  * Get a new query builder for the model's table.
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function newQuery()
 {
     $builder = parent::newQuery();
     // If I am using STI, and I am not the base class,
     // then filter on the class name.
     if (!$this->isRootModel()) {
         $builder->where(static::$table_type_field, get_class($this));
     }
     return $builder;
 }
Example #20
0
 /**
  * Add a basic where clause to the query.
  *
  * @param  string  $column
  * @param  string  $operator
  * @param  mixed   $value
  * @param  string  $boolean
  * @return \Illuminate\Database\Eloquent\Builder|static
  */
 public function where($column, $operator = null, $value = null, $boolean = 'and')
 {
     if ($column instanceof Closure) {
         $query = $this->model->newQuery();
         call_user_func($column, $query);
         $this->query->addNestedWhereQuery($query->getQuery(), $boolean);
     } else {
         $this->query->where($column, $operator, $value, $boolean);
     }
     return $this;
 }
 /**
  * Add a basic where clause to the query.
  *
  * @param  string  $column
  * @param  string  $operator
  * @param  mixed   $value
  * @param  string  $boolean
  * @return \Illuminate\Database\Eloquent\Builder|static
  */
 public function where($column, $operator = null, $value = null, $boolean = 'and')
 {
     if ($column instanceof Closure) {
         $query = $this->model->newQuery(false);
         call_user_func($column, $query);
         $this->query->addNestedWhereQuery($query->getQuery(), $boolean);
     } else {
         call_user_func_array(array($this->query, 'where'), func_get_args());
     }
     return $this;
 }
Example #22
0
 /**
  * Get a new query builder for the model's table.
  * Manipulate in case we need to convert geometrical fields to text.
  *
  * @param  bool  $excludeDeleted
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function newQuery($excludeDeleted = true)
 {
     if (!empty($this->geometry) && $this->geometryAsText === true) {
         $raw = '';
         foreach ($this->geometry as $column) {
             $raw .= 'AsText(`' . $this->table . '`.`' . $column . '`) as `' . $column . '`, ';
         }
         $raw = substr($raw, 0, -2);
         return parent::newQuery($excludeDeleted)->addSelect('*', DB::raw($raw));
     }
     return parent::newQuery($excludeDeleted);
 }
Example #23
0
 protected function makeModel()
 {
     $class = $this->model;
     if (!is_string($class) or !class_exists($class)) {
         throw new RepositoryException($class);
     }
     $this->instance = $this->app->make($class);
     if (!$this->instance instanceof Model) {
         throw new RepositoryException($class);
     }
     $this->query = $this->instance->newQuery();
 }
Example #24
0
 /**
  * Funcao para implementar os filtros dinamicos, 
  * definidos no arquivo de configuracao (modelconfig)
  * 
  * @param  boolean $excludeDeleted
  * @return Object
  */
 public function newQuery($excludeDeleted = true)
 {
     $filters = $this->_getDefaultFilter();
     $query = parent::newQuery($excludeDeleted = true);
     // Illuminate\Database\Eloquent\Builder
     // $query->whereHas('cod_paiss', function($querys){
     //     mdd(get_class($querys));
     //     $querys->where('ind_status', '=', 'A');
     // });
     foreach ($filters as $filter) {
         $query->whereRaw($filter);
     }
     return $query;
 }
Example #25
0
 /**
  * @param $id
  * @param $operator
  * @param $boolean
  *
  * @return $this
  */
 protected function whereIsBeforeOrAfter($id, $operator, $boolean)
 {
     if (NestedSet::isNode($id)) {
         $value = '?';
         $this->query->addBinding($id->getLft());
     } else {
         $valueQuery = $this->model->newQuery()->toBase()->select('_n.' . $this->model->getLftName())->from($this->model->getTable() . ' as _n')->where('_n.' . $this->model->getKeyName(), '=', $id);
         $this->query->mergeBindings($valueQuery);
         $value = '(' . $valueQuery->toSql() . ')';
     }
     list($lft, ) = $this->wrappedColumns();
     $this->query->whereRaw("{$lft} {$operator} {$value}", [], $boolean);
     return $this;
 }
Example #26
0
 /**
  * Carregar lista.
  */
 public function getList()
 {
     $context = new \Bugotech\Http\Context\Context();
     // Preparar queries
     $qcount = $this->model->newQuery()->select(DB::raw('count(*) recs'));
     $query = $this->model->newQuery();
     // Atribuir alias da tabela principal com A
     /*
             $q       = $query->getQuery();
             $q->from = sprintf('%s as a', $q->from);
             $query->setQuery($q);
             $q       = $qcount->getQuery();
             $q->from = sprintf('%s as a', $q->from);
             $qcount->setQuery($q);
             /**/
     // Filtros de contexto
     $this->applyWhereContext($query);
     $this->applyWhereContext($qcount);
     // Filtros (Query e Count)
     if ($context->searchQuery != '') {
         $search = new SearchModel($this->model, $this->searches);
         $items = $search->execute($context->searchQuery);
         $search->applyQuery($query, $items);
         $search->applyQuery($qcount, $items);
     }
     // Paginação
     $query->forPage($context->page, $context->pageSize);
     // Ordenação
     $context->defaultSort = $this->defaultSort;
     foreach ($context->sorts as $sort) {
         $query->orderBy($sort->column, $sort->dir);
     }
     // Carregar o número de registros do contexto
     $context->setCount(intval($qcount->first('recs')->recs));
     // Retornar
     return new IndexReturn($this->request, $query, $context);
 }
Example #27
0
 /**
  * Create a query on Eloquent\QueryBuilder.
  *
  * @param array $where
  * @param array $orderBy
  * @param int|null $limit
  * @param array|null $with
  * @param string $defaultOperator
  * @return $this|Builder|static
  */
 protected function createQuery(array $where, $orderBy = [], $limit = null, $with = null, $defaultOperator = '=')
 {
     $query = $this->model->newQuery();
     if ($with != null) {
         $query = $query->with($with);
     }
     foreach ($where as $field => $value) {
         if (is_array($value) && sizeof($value) == 2) {
             list($condition, $val) = $value;
             if ($condition == 'in') {
                 $query = $query->whereIn($field, $val);
             } else {
                 $query = $query->where($field, $condition, $val);
             }
         } else {
             if (is_array($value) && sizeof($value) == 3) {
                 list($field, $condition, $val) = $value;
                 if ($condition == 'in') {
                     $query = $query->whereIn($field, $val);
                 } else {
                     $query = $query->where($field, $condition, $val);
                 }
             } else {
                 if (is_array($value) && sizeof($value) == 4) {
                     list($operator, $field, $condition, $val) = $value;
                     if ($operator == 'or') {
                         $query = $query->orWhere($field, $condition, $val);
                     } else {
                         if ($operator == 'and') {
                             $query = $query->where($field, $condition, $val);
                         }
                     }
                 } else {
                     $query = $query->where($field, $defaultOperator, $value);
                 }
             }
         }
     }
     foreach ($orderBy as $value) {
         list($field, $order) = $value;
         $query = $query->orderBy($field, $order);
     }
     if ($limit != null) {
         $query = $query->limit($limit);
     }
     return $query;
 }
Example #28
0
 /**
  * Override the default query to do all the category joins
  *
  * @param boolean $excludeDeleted Include soft deleted columns
  *
  * @return object The query object
  */
 public function newQuery($excludeDeleted = true)
 {
     $query = parent::newQuery($excludeDeleted);
     $query->join('terms', 'term_taxonomy.term_id', '=', 'terms.term_id');
     return $query;
 }
Example #29
0
 /**
  * @return string
  */
 public function getSubtitle()
 {
     $query = $this->instance->newQuery();
     return $this->applyFilters($query);
 }
Example #30
0
 /**
  * Resets the query scope.
  *
  * @return mixed
  */
 public function resetScope()
 {
     $this->query = $this->model->newQuery();
 }