Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 23, 2018
1 parent 496dc2b commit e501d88
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1885,11 +1885,9 @@ public function value($column)
*/
public function get($columns = ['*'])
{
return collect(
$this->onceWithColumns($columns, function () {
return $this->processor->processSelect($this, $this->runSelect());
})
);
return collect($this->onceWithColumns($columns, function () {
return $this->processor->processSelect($this, $this->runSelect());
}));
}

/**
Expand Down Expand Up @@ -2085,10 +2083,15 @@ protected function enforceOrderBy()
*/
public function pluck($column, $key = null)
{
// First, we will need to select the results of the query accounting for the
// given columns / key. Once we have the results, we will be able to take
// the results and get the exact data that was requested for the query.
$queryResult = $this->onceWithColumns(
is_null($key) ? [$column] : [$column, $key],
function () {
return $this->processor->processSelect($this, $this->runSelect());
return $this->processor->processSelect(
$this, $this->runSelect()
);
}
);

Expand All @@ -2100,37 +2103,12 @@ function () {
// those directly in the "pluck" operations since the results from the DB
// are only keyed by the column itself. We'll strip the table out here.
$column = $this->stripTableForPluck($column);
$key = $this->stripTableForPluck($key);

if (is_array($queryResult[0])) {
return $this->pluckFromArrayColumn($queryResult, $column, $key);
} else {
return $this->pluckFromObjectColumn($queryResult, $column, $key);
}
}

/**
* Execute the given callback while selecting the given columns.
*
* After running the callback, the columns are reset to the original value.
*
* @param array $columns
* @param callable $callback
* @return mixed
*/
protected function onceWithColumns($columns, $callback)
{
$original = $this->columns;

if (is_null($original)) {
$this->columns = $columns;
}

$result = $callback();

$this->columns = $original;
$key = $this->stripTableForPluck($key);

return $result;
return is_array($queryResult[0])
? $this->pluckFromArrayColumn($queryResult, $column, $key)
: $this->pluckFromObjectColumn($queryResult, $column, $key);
}

/**
Expand Down Expand Up @@ -2375,6 +2353,30 @@ protected function setAggregate($function, $columns)
return $this;
}

/**
* Execute the given callback while selecting the given columns.
*
* After running the callback, the columns are reset to the original value.
*
* @param array $columns
* @param callable $callback
* @return mixed
*/
protected function onceWithColumns($columns, $callback)
{
$original = $this->columns;

if (is_null($original)) {
$this->columns = $columns;
}

$result = $callback();

$this->columns = $original;

return $result;
}

/**
* Insert a new record into the database.
*
Expand Down

0 comments on commit e501d88

Please sign in to comment.