add crud api global setting and make global api response and handle response web and api on bootstrap app

This commit is contained in:
arifal hidayat
2025-01-27 02:08:40 +07:00
parent 5d0965bd3b
commit f1aa8868be
8 changed files with 95 additions and 27 deletions

View File

@@ -3,6 +3,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
return Application::configure(basePath: dirname(__DIR__))
@@ -15,8 +16,13 @@ return Application::configure(basePath: dirname(__DIR__))
->withMiddleware(function (Middleware $middleware) {
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (HttpException $exception){
if($exception->getStatusCode() == 404) {
$exceptions->shouldRenderJsonWhen(function (Request $request, Throwable $th){
if($request->is('api/*')){
return true;
}
});
$exceptions->render(function (HttpException $exception, Request $request){
if($exception->getStatusCode() == 404 && $request->isNot('api/*')) {
return response()->view('pages.404',[],404);
}
});