Skip to content

Instantly share code, notes, and snippets.

@rizkytegar
Created May 3, 2024 04:27
Show Gist options
  • Save rizkytegar/b362c41409943617b4de0e8f76527bab to your computer and use it in GitHub Desktop.
Save rizkytegar/b362c41409943617b4de0e8f76527bab to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (NotFoundHttpException $e, Request $request) {
if ($request->is('*')) {
$xmlData =
'<error>
<code>404</code>
<message>Not Found</message>
</error>';
return response($xmlData, 404)
->header('Content-Type', 'application/xml');
}
});
$exceptions->render(function (MethodNotAllowedHttpException $e, Request $request) {
if ($request->is('*')) {
$xmlData = '<error>
<code>405</code>
<message>Method is not supported for this route</message>
</error>';
return response($xmlData, 405)
->header('Content-Type', 'application/xml');
}
});
})->create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment