51 lines
2.1 KiB
PHP
51 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Http\Middleware\CheckRole;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
use Illuminate\Http\Exceptions\PostTooLargeException;
|
|
use Illuminate\Http\Request;
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
web: __DIR__.'/../routes/web.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withCommands([
|
|
__DIR__.'/../app/Console/Commands',
|
|
])
|
|
->withMiddleware(function (Middleware $middleware): void {
|
|
$middleware->alias([
|
|
'role' => CheckRole::class,
|
|
]);
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions): void {
|
|
$exceptions->renderable(function (PostTooLargeException $e, Request $request) {
|
|
$contentLength = (int) $request->server('CONTENT_LENGTH', 0);
|
|
$contentLengthMb = $contentLength > 0 ? $contentLength / 1048576 : 0;
|
|
$postMaxSize = ini_get('post_max_size') ?: 'unknown';
|
|
$uploadMaxSize = ini_get('upload_max_filesize') ?: 'unknown';
|
|
$backUrl = url()->previous() ?: url('/');
|
|
|
|
if ($request->expectsJson()) {
|
|
return response()->json([
|
|
'message' => __('The request body is too large. Increase PHP post_max_size and upload_max_filesize (e.g. `composer run dev` or php.ini).'),
|
|
'content_length_bytes' => $contentLength,
|
|
'post_max_size' => $postMaxSize,
|
|
'upload_max_filesize' => $uploadMaxSize,
|
|
], 413);
|
|
}
|
|
|
|
// ValidatePostSize runs before the web middleware group (no session yet), so a flash on redirect is often lost.
|
|
return response()
|
|
->view('errors.post-too-large', [
|
|
'contentLengthMb' => $contentLengthMb,
|
|
'postMaxSize' => $postMaxSize,
|
|
'uploadMaxSize' => $uploadMaxSize,
|
|
'backUrl' => $backUrl,
|
|
], 413);
|
|
});
|
|
})->create();
|