From 146c275c337b40aa5d060badfc0fa8c97ee39dd9 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 13 Sep 2024 20:50:02 +0800 Subject: [PATCH] [11.x] Fixes out of memory issue running `route:cache` with ServeFile fixes #52779 Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Filesystem/FilesystemServiceProvider.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Filesystem/FilesystemServiceProvider.php b/src/Illuminate/Filesystem/FilesystemServiceProvider.php index a6ad8e1a7b34..aa9f9846cd21 100644 --- a/src/Illuminate/Filesystem/FilesystemServiceProvider.php +++ b/src/Illuminate/Filesystem/FilesystemServiceProvider.php @@ -87,16 +87,18 @@ protected function serveFiles() continue; } - $this->app->booted(function () use ($disk, $config) { + $this->app->booted(function ($app) use ($disk, $config) { $uri = isset($config['url']) ? rtrim(parse_url($config['url'])['path'], '/') : '/storage'; - Route::get($uri.'/{path}', function (Request $request, string $path) use ($disk, $config) { + $isProduction = $app->isProduction(); + + Route::get($uri.'/{path}', function (Request $request, string $path) use ($disk, $config, $isProduction) { return (new ServeFile( $disk, $config, - $this->app->isProduction() + $isProduction ))($request, $path); })->where('path', '.*')->name('storage.'.$disk); });