/**
  * 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
 /**
  * @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;
 }