From 2af31d0e5f3f5e50769d7cf7552ed37319282650 Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski Date: Fri, 10 Apr 2026 15:56:31 +0200 Subject: [PATCH] Rename local_public disk back to public and store avatars/logos on public disk The public disk was accidentally removed during the Laravel 11 upgrade and re-added as local_public in the FileDisk refactor. Restoring the standard Laravel name avoids breaking Spatie MediaLibrary expectations and simplifies the v2-to-v3 upgrade path. User avatars and company logos now explicitly use the public disk via registerMediaCollections(), keeping them web-accessible while the default media disk remains private for sensitive documents like PDFs and receipts. The v3 upgrade migration renames the system disk entry and any alpha media records from local_public back to public. --- app/Models/Company.php | 7 +++++ app/Models/User.php | 7 +++++ app/Services/FileDiskService.php | 2 +- config/filesystems.php | 2 +- ...12_02_090527_update_crater_version_400.php | 2 +- .../2026_04_07_001104_upgrade_to_v3.php | 26 +++++++++++++++++++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/Models/Company.php b/app/Models/Company.php index 382cbe9b..d7365a78 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -17,6 +17,13 @@ class Company extends Model implements HasMedia use HasFactory; use InteractsWithMedia; + public function registerMediaCollections(): void + { + $this->addMediaCollection('logo') + ->useDisk('public') + ->singleFile(); + } + protected $guarded = [ 'id', ]; diff --git a/app/Models/User.php b/app/Models/User.php index 898a5264..5ec2414e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -28,6 +28,13 @@ class User extends Authenticatable implements HasMedia use InteractsWithMedia; use Notifiable; + public function registerMediaCollections(): void + { + $this->addMediaCollection('admin_avatar') + ->useDisk('public') + ->singleFile(); + } + /** * The attributes that are mass assignable. * diff --git a/app/Services/FileDiskService.php b/app/Services/FileDiskService.php index b24d1fe1..af2ac4bf 100644 --- a/app/Services/FileDiskService.php +++ b/app/Services/FileDiskService.php @@ -63,7 +63,7 @@ class FileDiskService public function getDiskName(FileDisk $disk): string { if ($disk->isSystem()) { - return $disk->name === 'local_public' ? 'local_public' : 'local'; + return $disk->name === 'public' ? 'public' : 'local'; } return 'disk_'.$disk->id; diff --git a/config/filesystems.php b/config/filesystems.php index 25a7d2e4..20e61eed 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -37,7 +37,7 @@ return [ 'report' => false, ], - 'local_public' => [ + 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', diff --git a/database/migrations/2020_12_02_090527_update_crater_version_400.php b/database/migrations/2020_12_02_090527_update_crater_version_400.php index c287b5b5..1c8610e6 100644 --- a/database/migrations/2020_12_02_090527_update_crater_version_400.php +++ b/database/migrations/2020_12_02_090527_update_crater_version_400.php @@ -71,7 +71,7 @@ return new class extends Migration FileDisk::create([ 'credentials' => json_encode($publicDisk), - 'name' => 'local_public', + 'name' => 'public', 'type' => 'SYSTEM', 'driver' => 'local', 'set_as_default' => false, diff --git a/database/migrations/2026_04_07_001104_upgrade_to_v3.php b/database/migrations/2026_04_07_001104_upgrade_to_v3.php index 0915878c..e9b24556 100644 --- a/database/migrations/2026_04_07_001104_upgrade_to_v3.php +++ b/database/migrations/2026_04_07_001104_upgrade_to_v3.php @@ -11,6 +11,7 @@ return new class extends Migration public function up(): void { $this->migrateMediaDiskReferences(); + $this->renameSystemDisk(); } /** @@ -25,6 +26,12 @@ return new class extends Migration ->where('disk', 'temp_local') ->update(['disk' => 'local']); + // Any v3 alpha installs that stored media with the 'local_public' name + // need updating to 'public' (the standard Laravel disk name). + DB::table('media') + ->where('disk', 'local_public') + ->update(['disk' => 'public']); + // temp_s3, temp_dropbox, etc. for remote disks — map to disk_{id} $remotePrefixes = ['temp_s3', 'temp_dropbox', 'temp_doSpaces', 'temp_s3compat']; @@ -43,8 +50,23 @@ return new class extends Migration } } + /** + * The v4.0.0 migration created the system disk as 'local_public'. + * Rename it to 'public' to match the standard Laravel disk name. + */ + private function renameSystemDisk(): void + { + DB::table('file_disks') + ->where('name', 'local_public') + ->update(['name' => 'public']); + } + public function down(): void { + DB::table('file_disks') + ->where('name', 'public') + ->update(['name' => 'local_public']); + // Reverse: map disk_{id} back to temp_{driver} $fileDiskIds = DB::table('file_disks') ->whereNotIn('type', ['SYSTEM']) @@ -56,6 +78,10 @@ return new class extends Migration ->update(['disk' => 'temp_'.$disk->driver]); } + DB::table('media') + ->where('disk', 'public') + ->update(['disk' => 'local_public']); + DB::table('media') ->where('disk', 'local') ->update(['disk' => 'temp_local']);