Skip to content

Commit

Permalink
rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 14, 2021
1 parent b1fd05e commit 29c7dae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Container\Container;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Database\NoRecordsFoundException;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;

Expand Down Expand Up @@ -150,24 +150,24 @@ public function first($columns = ['*'])
}

/**
* Execute the query and get the first result if it's the sole.
* Execute the query and get the first result if it's the sole matching record.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Model|object|static|null
*
* @throws \Illuminate\Database\NoRecordsFoundException
* @throws \Illuminate\Database\RecordsNotFoundException
* @throws \Illuminate\Database\MultipleRecordsFoundException
*/
public function sole($columns = ['*'])
{
$result = $this->take(2)->get($columns);

if ($result->isEmpty()) {
throw new NoRecordsFoundException();
throw new RecordsNotFoundException;
}

if ($result->count() > 1) {
throw new MultipleRecordsFoundException();
throw new MultipleRecordsFoundException;
}

return $result->first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use RuntimeException;

class NoRecordsFoundException extends RuntimeException
class RecordsNotFoundException extends RuntimeException
{
//
}
4 changes: 2 additions & 2 deletions tests/Integration/Database/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Database\NoRecordsFoundException;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -52,7 +52,7 @@ public function testSoleFailsForMultipleRecords()

public function testSoleFailsIfNoRecords()
{
$this->expectException(NoRecordsFoundException::class);
$this->expectException(RecordsNotFoundException::class);

DB::table('posts')->where('title', 'Baz Post')->sole();
}
Expand Down

0 comments on commit 29c7dae

Please sign in to comment.