Skip to content

Commit

Permalink
Ensure that the model class name is properly set. (#36011)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Michot committed Jan 23, 2021
1 parent cc03df3 commit 72a44d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public function sole($columns = ['*'])
try {
return $this->baseSole($columns);
} catch (RecordsNotFoundException $exception) {
throw new ModelNotFoundException($this->model);
throw (new ModelNotFoundException)->setModel(get_class($this->model));
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Integration/Database/EloquentWhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ public function testSoleFailsForMultipleRecords()

public function testSoleFailsIfNoRecords()
{
$this->expectException(ModelNotFoundException::class);
try {
UserWhereTest::where('name', 'test-name')->sole();
} catch (ModelNotFoundException $exception) {
//
}

UserWhereTest::where('name', 'test-name')->sole();
$this->assertSame(UserWhereTest::class, $exception->getModel());
}
}

Expand Down

0 comments on commit 72a44d3

Please sign in to comment.