withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->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();