Skip to content

Commit bf0ebd6

Browse files
committed
Merge branch '9.x' of https://github.com/hailwood/framework into hailwood-9.x
2 parents aac0da0 + 1846fb3 commit bf0ebd6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,20 @@ public function value($column)
614614
}
615615
}
616616

617+
/**
618+
* Get a single column's value from the first result of a query if it's the sole matching record.
619+
*
620+
* @param string|\Illuminate\Database\Query\Expression $column
621+
* @return mixed
622+
*
623+
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException<\Illuminate\Database\Eloquent\Model>
624+
* @throws \Illuminate\Database\MultipleRecordsFoundException
625+
*/
626+
public function soleValue($column)
627+
{
628+
return $this->sole([$column])->{Str::afterLast($column, '.')};
629+
}
630+
617631
/**
618632
* Get a single column's value from the first result of the query or throw an exception.
619633
*

src/Illuminate/Database/Query/Builder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,22 @@ public function value($column)
25162516
return count($result) > 0 ? reset($result) : null;
25172517
}
25182518

2519+
/**
2520+
* Get a single column's value from the first result of a query if it's the sole matching record.
2521+
*
2522+
* @param string $column
2523+
* @return mixed
2524+
*
2525+
* @throws \Illuminate\Database\RecordsNotFoundException
2526+
* @throws \Illuminate\Database\MultipleRecordsFoundException
2527+
*/
2528+
public function soleValue($column)
2529+
{
2530+
$result = (array) $this->sole([$column]);
2531+
2532+
return reset($result);
2533+
}
2534+
25192535
/**
25202536
* Execute the query as a "select" statement.
25212537
*

0 commit comments

Comments
 (0)