diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 9d017cff5968..e4d65a68d931 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -26,14 +26,14 @@ class Builder { * * @var array */ - protected $eagerLoad = array(); + protected $eagerLoad = []; /** * All of the registered builder macros. * * @var array */ - protected $macros = array(); + protected $macros = []; /** * A replacement for the typical delete function. @@ -47,10 +47,10 @@ class Builder { * * @var array */ - protected $passthru = array( + protected $passthru = [ 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'count', 'min', 'max', 'avg', 'sum', 'exists', 'getBindings', - ); + ]; /** * Create a new Eloquent query builder instance. @@ -70,7 +70,7 @@ public function __construct(QueryBuilder $query) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function find($id, $columns = array('*')) + public function find($id, $columns = ['*']) { if (is_array($id)) { @@ -89,7 +89,7 @@ public function find($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|Collection|static */ - public function findMany($id, $columns = array('*')) + public function findMany($id, $columns = ['*']) { if (empty($id)) return $this->model->newCollection(); @@ -107,7 +107,7 @@ public function findMany($id, $columns = array('*')) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function findOrFail($id, $columns = array('*')) + public function findOrFail($id, $columns = ['*']) { if ( ! is_null($model = $this->find($id, $columns))) return $model; @@ -120,7 +120,7 @@ public function findOrFail($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function first($columns = array('*')) + public function first($columns = ['*']) { return $this->take(1)->get($columns)->first(); } @@ -133,7 +133,7 @@ public function first($columns = array('*')) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function firstOrFail($columns = array('*')) + public function firstOrFail($columns = ['*']) { if ( ! is_null($model = $this->first($columns))) return $model; @@ -146,7 +146,7 @@ public function firstOrFail($columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ - public function get($columns = array('*')) + public function get($columns = ['*']) { $models = $this->getModels($columns); @@ -169,7 +169,7 @@ public function get($columns = array('*')) */ public function pluck($column) { - $result = $this->first(array($column)); + $result = $this->first([$column]); if ($result) return $result->{$column}; } @@ -216,7 +216,7 @@ public function lists($column, $key = null) { foreach ($results as $key => &$value) { - $fill = array($column => $value); + $fill = [$column => $value]; $value = $this->model->newFromBuilder($fill)->$column; } @@ -232,7 +232,7 @@ public function lists($column, $key = null) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function paginate($perPage = null, $columns = array('*')) + public function paginate($perPage = null, $columns = ['*']) { $perPage = $perPage ?: $this->model->getPerPage(); @@ -292,7 +292,7 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function simplePaginate($perPage = null, $columns = array('*')) + public function simplePaginate($perPage = null, $columns = ['*']) { $paginator = $this->query->getConnection()->getPaginator(); @@ -324,7 +324,7 @@ public function update(array $values) * @param array $extra * @return int */ - public function increment($column, $amount = 1, array $extra = array()) + public function increment($column, $amount = 1, array $extra = []) { $extra = $this->addUpdatedAtColumn($extra); @@ -339,7 +339,7 @@ public function increment($column, $amount = 1, array $extra = array()) * @param array $extra * @return int */ - public function decrement($column, $amount = 1, array $extra = array()) + public function decrement($column, $amount = 1, array $extra = []) { $extra = $this->addUpdatedAtColumn($extra); @@ -403,7 +403,7 @@ public function onDelete(Closure $callback) * @param array $columns * @return \Illuminate\Database\Eloquent\Model[] */ - public function getModels($columns = array('*')) + public function getModels($columns = ['*']) { // First, we will simply get the raw results from the query builders which we // can use to populate an array with Eloquent models. We will pass columns @@ -412,7 +412,7 @@ public function getModels($columns = array('*')) $connection = $this->model->getConnectionName(); - $models = array(); + $models = []; // Once we have the results, we can spin through them and instantiate a fresh // model instance for each records we retrieved from the database. We will @@ -515,7 +515,7 @@ public function getRelation($relation) */ protected function nestedRelations($relation) { - $nested = array(); + $nested = []; // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations @@ -566,7 +566,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - call_user_func_array(array($this->query, 'where'), func_get_args()); + call_user_func_array([$this->query, 'where'], func_get_args()); } return $this; @@ -588,11 +588,11 @@ public function orWhere($column, $operator = null, $value = null) /** * Add a relationship count condition to the query. * - * @param string $relation - * @param string $operator - * @param int $count - * @param string $boolean - * @param \Closure $callback + * @param string $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) @@ -606,6 +606,20 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ return $this->addHasWhere($query, $relation, $operator, $count, $boolean); } + + /** + * Add a relationship count condition to the query + * + * @param string $relation + * @param string $boolean + * @param null $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function hasNot($relation, $boolean = 'and', $callback = null) + { + return $this->has($relation, '<', 1, $boolean, $callback); + } + /** * Add a relationship count condition to the query with where clauses. * @@ -620,6 +634,19 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count return $this->has($relation, $operator, $count, 'and', $callback); } + + /** + * Add a relationship count condition to the query with where clauses. + * + * @param string $relation + * @param \Closure $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function whereHasNot($relation, Closure $callback) + { + return $this->hasNot($relation, 'and', $callback); + } + /** * Add a relationship count condition to the query with an "or". * @@ -731,7 +758,7 @@ public function with($relations) */ protected function parseRelations(array $relations) { - $results = array(); + $results = []; foreach ($relations as $name => $constraints) { @@ -742,7 +769,7 @@ protected function parseRelations(array $relations) { $f = function() {}; - list($name, $constraints) = array($constraints, $f); + list($name, $constraints) = [$constraints, $f]; } // We need to separate out any nested includes. Which allows the developers @@ -765,7 +792,7 @@ protected function parseRelations(array $relations) */ protected function parseNested($name, $results) { - $progress = array(); + $progress = []; // If the relation has already been set on the result array, we will not set it // again, since that would override any constraints that were already placed @@ -794,7 +821,7 @@ protected function callScope($scope, $parameters) { array_unshift($parameters, $this); - return call_user_func_array(array($this->model, $scope), $parameters) ?: $this; + return call_user_func_array([$this->model, $scope], $parameters) ?: $this; } /** @@ -907,7 +934,7 @@ public function __call($method, $parameters) return $this->callScope($scope, $parameters); } - $result = call_user_func_array(array($this->query, $method), $parameters); + $result = call_user_func_array([$this->query, $method], $parameters); return in_array($method, $this->passthru) ? $result : $this; }