Skip to content

Commit

Permalink
Merge branch '9.x' of https://github.com/hailwood/framework into hail…
Browse files Browse the repository at this point in the history
…wood-9.x
  • Loading branch information
taylorotwell committed Mar 7, 2022
2 parents aac0da0 + 1846fb3 commit bf0ebd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,20 @@ public function value($column)
}
}

/**
* Get a single column's value from the first result of a query if it's the sole matching record.
*
* @param string|\Illuminate\Database\Query\Expression $column
* @return mixed
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException<\Illuminate\Database\Eloquent\Model>
* @throws \Illuminate\Database\MultipleRecordsFoundException
*/
public function soleValue($column)
{
return $this->sole([$column])->{Str::afterLast($column, '.')};
}

/**
* Get a single column's value from the first result of the query or throw an exception.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,22 @@ public function value($column)
return count($result) > 0 ? reset($result) : null;
}

/**
* Get a single column's value from the first result of a query if it's the sole matching record.
*
* @param string $column
* @return mixed
*
* @throws \Illuminate\Database\RecordsNotFoundException
* @throws \Illuminate\Database\MultipleRecordsFoundException
*/
public function soleValue($column)
{
$result = (array) $this->sole([$column]);

return reset($result);
}

/**
* Execute the query as a "select" statement.
*
Expand Down

0 comments on commit bf0ebd6

Please sign in to comment.