diff --git a/database/seeders/TenantSeeder.php b/database/seeders/TenantSeeder.php index 68ae64b..32c95f2 100644 --- a/database/seeders/TenantSeeder.php +++ b/database/seeders/TenantSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Domains\Attachable\Services\AttachmentService; use App\Domains\Tenant\Models\Tenant; use App\Domains\Tenant\Services\TenantService; use Illuminate\Database\Seeder; @@ -9,9 +10,16 @@ use Illuminate\Http\UploadedFile; class TenantSeeder extends Seeder { - public function __construct(protected TenantService $tenantService) - { - } + private const SONDER_MAIN_CAROUSEL_IMAGES = [ + '01-urban-team.png', + '02-running-shoes.png', + '03-streetwear.png', + '04-football-training.png', + '05-activewear-essentials.png', + '06-city-runners.png', + ]; + + public function __construct(protected TenantService $tenantService) {} /** * Run the database seeds. @@ -21,7 +29,7 @@ class TenantSeeder extends Seeder // Check if tenant 'sonder' already exists and delete it to prevent duplicates $existing = Tenant::query()->where('codigo', 'sonder')->first(); if ($existing) { - $attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class); + $attachmentService = app(AttachmentService::class); if ($existing->headerLogo) { try { $attachmentService->delete($existing->headerLogo); @@ -36,6 +44,13 @@ class TenantSeeder extends Seeder // Ignore exception on cleanup } } + foreach ($existing->mainCarouselImages as $mainCarouselImage) { + try { + $attachmentService->delete($mainCarouselImage); + } catch (\Throwable $e) { + // Ignore exception on cleanup + } + } $existing->delete(); } @@ -72,7 +87,24 @@ class TenantSeeder extends Seeder true ); - $tenant = $this->tenantService->create([ + $mainCarouselImages = []; + foreach (self::SONDER_MAIN_CAROUSEL_IMAGES as $filename) { + $imagePath = public_path("images/sonder-main-carousel/{$filename}"); + + if (! file_exists($imagePath)) { + throw new \RuntimeException("Image not found at path: {$imagePath}"); + } + + $mainCarouselImages[] = new UploadedFile( + $imagePath, + $filename, + 'image/png', + null, + true + ); + } + + $this->tenantService->create([ 'codigo' => 'sonder', 'nombre' => 'Sonder', 'dominio' => 'localhost', @@ -84,26 +116,30 @@ class TenantSeeder extends Seeder 'footer_bg_color' => '#313131', 'header_logo' => $headerLogo, 'footer_logo' => $footerLogo, + 'main_carousel_images' => $mainCarouselImages, ]); // Check if tenant 'fiesta_futbol_infantil' already exists $existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first(); if ($existingFiesta) { - $attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class); + $attachmentService = app(AttachmentService::class); if ($existingFiesta->headerLogo) { try { $attachmentService->delete($existingFiesta->headerLogo); - } catch (\Throwable $e) {} + } catch (\Throwable $e) { + } } if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) { try { $attachmentService->delete($existingFiesta->footerLogo); - } catch (\Throwable $e) {} + } catch (\Throwable $e) { + } } if ($existingFiesta->heroBgImage) { try { $attachmentService->delete($existingFiesta->heroBgImage); - } catch (\Throwable $e) {} + } catch (\Throwable $e) { + } } $existingFiesta->delete(); } diff --git a/public/images/sonder-main-carousel/01-urban-team.png b/public/images/sonder-main-carousel/01-urban-team.png new file mode 100644 index 0000000..c0dc214 Binary files /dev/null and b/public/images/sonder-main-carousel/01-urban-team.png differ diff --git a/public/images/sonder-main-carousel/02-running-shoes.png b/public/images/sonder-main-carousel/02-running-shoes.png new file mode 100644 index 0000000..d50ab7a Binary files /dev/null and b/public/images/sonder-main-carousel/02-running-shoes.png differ diff --git a/public/images/sonder-main-carousel/03-streetwear.png b/public/images/sonder-main-carousel/03-streetwear.png new file mode 100644 index 0000000..e6c6be8 Binary files /dev/null and b/public/images/sonder-main-carousel/03-streetwear.png differ diff --git a/public/images/sonder-main-carousel/04-football-training.png b/public/images/sonder-main-carousel/04-football-training.png new file mode 100644 index 0000000..477ddd3 Binary files /dev/null and b/public/images/sonder-main-carousel/04-football-training.png differ diff --git a/public/images/sonder-main-carousel/05-activewear-essentials.png b/public/images/sonder-main-carousel/05-activewear-essentials.png new file mode 100644 index 0000000..d906749 Binary files /dev/null and b/public/images/sonder-main-carousel/05-activewear-essentials.png differ diff --git a/public/images/sonder-main-carousel/06-city-runners.png b/public/images/sonder-main-carousel/06-city-runners.png new file mode 100644 index 0000000..556ee59 Binary files /dev/null and b/public/images/sonder-main-carousel/06-city-runners.png differ diff --git a/tests/Feature/Seeders/TenantSeederTest.php b/tests/Feature/Seeders/TenantSeederTest.php new file mode 100644 index 0000000..60d0e56 --- /dev/null +++ b/tests/Feature/Seeders/TenantSeederTest.php @@ -0,0 +1,38 @@ +seed(TenantSeeder::class); + + $tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail(); + $images = $tenant->mainCarouselImages()->get(); + + $this->assertSame([ + '01-urban-team.png', + '02-running-shoes.png', + '03-streetwear.png', + '04-football-training.png', + '05-activewear-essentials.png', + '06-city-runners.png', + ], $images->pluck('filename')->all()); + $this->assertSame([0, 1, 2, 3, 4, 5], $images->pluck('pivot.orden')->all()); + + foreach ($images as $image) { + Storage::disk('s3')->assertExists($image->path); + } + } +}