From 9cfa2e1664ee09149676861733704a75dde15e70 Mon Sep 17 00:00:00 2001 From: husanjon Date: Tue, 28 Apr 2026 16:13:08 +0500 Subject: [PATCH] storage url o'zgartirildi --- app/Console/Commands/StorageHealthCheck.php | 49 +++++++++++++++++++ app/Support/Uploads.php | 10 ++++ config/filesystems.php | 2 +- .../views/dashboard/layouts/scripts.blade.php | 17 +++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/StorageHealthCheck.php diff --git a/app/Console/Commands/StorageHealthCheck.php b/app/Console/Commands/StorageHealthCheck.php new file mode 100644 index 0000000..b16d00f --- /dev/null +++ b/app/Console/Commands/StorageHealthCheck.php @@ -0,0 +1,49 @@ +argument('disk') ?: config('filesystems.default'); + $path = 'healthcheck/' . now()->format('YmdHis') . '-' . uniqid() . '.txt'; + + $this->line('default=' . config('filesystems.default')); + $this->line('disk=' . $disk); + $this->line('endpoint=' . (config("filesystems.disks.{$disk}.endpoint") ?: '-')); + $this->line('url=' . (config("filesystems.disks.{$disk}.url") ?: '-')); + $this->line('bucket=' . (config("filesystems.disks.{$disk}.bucket") ?: '-')); + $this->line('path_style=' . json_encode(config("filesystems.disks.{$disk}.use_path_style_endpoint"))); + + try { + $stored = Storage::disk($disk)->put($path, 'ok'); + + if (!$stored) { + $this->error("put=false path={$path}"); + return self::FAILURE; + } + + $exists = Storage::disk($disk)->exists($path); + $this->line('put=ok'); + $this->line('exists=' . ($exists ? 'yes' : 'no')); + $this->line('public_url=' . Storage::disk($disk)->url($path)); + + Storage::disk($disk)->delete($path); + $this->line('delete=ok'); + } catch (Throwable $e) { + $this->error(get_class($e) . ': ' . $e->getMessage()); + return self::FAILURE; + } + + return self::SUCCESS; + } +} diff --git a/app/Support/Uploads.php b/app/Support/Uploads.php index a29ec32..a283488 100644 --- a/app/Support/Uploads.php +++ b/app/Support/Uploads.php @@ -10,12 +10,17 @@ class Uploads { public static function store(UploadedFile $file, string $path, ?string $disk = null): string { + $diskName = $disk ?: config('filesystems.default'); $storedPath = $disk ? $file->store($path, $disk) : $file->store($path); if (!$storedPath) { throw new RuntimeException("File upload failed: {$path}"); } + if (!Storage::disk($diskName)->exists($storedPath)) { + throw new RuntimeException("Uploaded file was not found on disk [{$diskName}]: {$storedPath}"); + } + return $storedPath; } @@ -28,5 +33,10 @@ class Uploads if (!$stored) { throw new RuntimeException("File upload failed: {$path}"); } + + $diskName = $disk ?: config('filesystems.default'); + if (!Storage::disk($diskName)->exists($path)) { + throw new RuntimeException("Uploaded file was not found on disk [{$diskName}]: {$path}"); + } } } diff --git a/config/filesystems.php b/config/filesystems.php index 0c1eae8..8c215d3 100755 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -13,7 +13,7 @@ return [ | */ - 'default' => env('FILESYSTEM_DISK', 'local'), + 'default' => env('FILESYSTEM_DISK', env('FILESYSTEM_DRIVER', 's3')), /* |-------------------------------------------------------------------------- diff --git a/resources/views/dashboard/layouts/scripts.blade.php b/resources/views/dashboard/layouts/scripts.blade.php index 88bd113..ddd6eb1 100755 --- a/resources/views/dashboard/layouts/scripts.blade.php +++ b/resources/views/dashboard/layouts/scripts.blade.php @@ -21,6 +21,23 @@