Beispiel #1
0
 /**
  * Add a nested where statement to the query.
  *
  * @param  \Closure $callback
  * @param  string   $boolean
  * @return \Waavi\Model\Builder
  */
 public function whereRelatedNested(Closure $callback, $boolean = 'and')
 {
     // To handle nested queries we'll actually create a brand new query instance
     // and pass it off to the Closure that we have. The Closure can simply do
     // do whatever it wants to a query then we will store it for compiling.
     $type = 'Nested';
     $builder = new Builder($this->query->newQuery());
     $builder->setModel($this->model);
     call_user_func($callback, $builder);
     // Once we have let the Closure do its things, we can gather the bindings on
     // the nested query builder and merge them into these bindings since they
     // need to get extracted out of the children and assigned to the array.
     $query = $builder->getQuery();
     if (count($query->wheres)) {
         $this->getQuery()->wheres[] = compact('type', 'query', 'boolean');
         $this->getQuery()->mergeBindings($query);
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Get a new query builder for the model's table.
  * Overriden from {@link \Model\Eloquent} to allow for filtering on related models attributes.
  *
  * @param  bool  $excludeDeleted
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function newQuery($excludeDeleted = true)
 {
     $builder = new Builder($this->newBaseQueryBuilder());
     // Once we have the query builders, we will set the model instances so the
     // builder can easily access any information it may need from the model
     // while it is constructing and executing various queries against it.
     $builder->setModel($this)->with($this->with);
     if ($excludeDeleted and $this->softDelete) {
         $builder->whereNull($this->getQualifiedDeletedAtColumn());
     }
     return $builder;
 }