File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -614,6 +614,20 @@ public function value($column)
614
614
}
615
615
}
616
616
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
+
617
631
/**
618
632
* Get a single column's value from the first result of the query or throw an exception.
619
633
*
Original file line number Diff line number Diff line change @@ -2516,6 +2516,22 @@ public function value($column)
2516
2516
return count ($ result ) > 0 ? reset ($ result ) : null ;
2517
2517
}
2518
2518
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
+
2519
2535
/**
2520
2536
* Execute the query as a "select" statement.
2521
2537
*
You can’t perform that action at this time.
0 commit comments