Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore custom "not found" Exception messages. #58

Merged
merged 10 commits into from
Jul 12, 2024
62 changes: 0 additions & 62 deletions app/Exceptions/Handler.php

This file was deleted.

11 changes: 10 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
Expand All @@ -22,5 +24,12 @@
//
})
->withExceptions(function (Exceptions $exceptions) {
//
$exceptions->render(function (NotFoundHttpException $e, \Illuminate\Http\Request $request) {
if ($request->wantsJson() && $e->getPrevious() instanceof ModelNotFoundException) {
return response()->json([
'message' =>
sprintf('Requested %s couldn\'t be found.', class_basename($e->getPrevious()->getModel())),
], 404);
}
});
})->create();
Loading