Illuminate\Database\Eloquent\Model::newQuery PHP Method

newQuery() public method

Get a new query builder for the model's table.
public newQuery ( ) : Builder
return Builder
    public function newQuery()
    {
        $builder = $this->newQueryWithoutScopes();
        foreach ($this->getGlobalScopes() as $identifier => $scope) {
            $builder->withGlobalScope($identifier, $scope);
        }
        return $builder;
    }

Usage Example

 /**
  * 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);
         }
     });
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::newQuery
Model