From 4f5e91eac3f431c252c1e918c9ba555ef4a342ff Mon Sep 17 00:00:00 2001 From: Pete Bishop <9081809+PeteBishwhip@users.noreply.github.com> Date: Wed, 27 May 2026 14:53:21 +0100 Subject: [PATCH] Report MultipleRecordsFoundException from sole() --- src/Illuminate/Foundation/Exceptions/Handler.php | 2 -- tests/Foundation/FoundationExceptionsHandlerTest.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 811dc10bedc2..fde694da7971 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -17,7 +17,6 @@ use Illuminate\Contracts\Foundation\ExceptionRenderer; use Illuminate\Contracts\Support\Responsable; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Database\MultipleRecordsFoundException; use Illuminate\Database\RecordNotFoundException; use Illuminate\Database\RecordsNotFoundException; use Illuminate\Foundation\Exceptions\Renderer\Renderer; @@ -161,7 +160,6 @@ class Handler implements ExceptionHandlerContract HttpException::class, HttpResponseException::class, ModelNotFoundException::class, - MultipleRecordsFoundException::class, OriginMismatchException::class, RecordNotFoundException::class, RecordsNotFoundException::class, diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index a02a144ff6ee..c031753e194c 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -14,6 +14,7 @@ use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; use Illuminate\Contracts\Support\Responsable; use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Database\MultipleRecordsFoundException; use Illuminate\Database\RecordsNotFoundException; use Illuminate\Foundation\Exceptions\Handler; use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling; @@ -393,6 +394,15 @@ public function testRecordsNotFoundReturns404WithoutReporting() $this->handler->report(new RecordsNotFoundException); } + public function testMultipleRecordsFoundIsReported() + { + $logger = m::mock(LoggerInterface::class); + $this->container->instance(LoggerInterface::class, $logger); + $logger->shouldReceive('error')->withArgs(['2 records were found.', m::hasKey('exception')])->once(); + + $this->handler->report(new MultipleRecordsFoundException(2)); + } + public function testItReturnsSpecificErrorViewIfExists() { $viewFactory = m::mock(ViewFactory::class);