Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 57 additions & 30 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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))
{
Expand All @@ -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();

Expand All @@ -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;

Expand All @@ -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();
}
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -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};
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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.
*
Expand All @@ -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".
*
Expand Down Expand Up @@ -731,7 +758,7 @@ public function with($relations)
*/
protected function parseRelations(array $relations)
{
$results = array();
$results = [];

foreach ($relations as $name => $constraints)
{
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

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