60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use App\Domains\Tenant\Services\WebsiteExtraService;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Http\UploadedFile;
|
|
use RuntimeException;
|
|
|
|
class OnticketImmersiveHeroCarouselSeeder extends Seeder
|
|
{
|
|
private const IMAGES = [
|
|
'onticket_hero_carousel_1.png',
|
|
'onticket_hero_carousel_2.png',
|
|
'onticket_hero_carousel_3.avif',
|
|
'onticket_hero_carousel_4.jfif',
|
|
'onticket_hero_carousel_5.jfif',
|
|
'onticket_hero_carousel_6.jfif',
|
|
'onticket_hero_carousel_7.avif',
|
|
'onticket_hero_carousel_8.avif',
|
|
];
|
|
|
|
public function __construct(private readonly WebsiteExtraService $websiteExtraService) {}
|
|
|
|
public function run(): void
|
|
{
|
|
$tenant = Tenant::query()->where('codigo', 'onticket')->first();
|
|
|
|
if ($tenant?->storefront_website_type_code !== 'onticket_multi_event') {
|
|
return;
|
|
}
|
|
|
|
if ($tenant->websiteExtras()->whereHas(
|
|
'websiteTypeExtra',
|
|
fn ($query) => $query->where('codigo', 'immersiveHeroCarousel')
|
|
)->exists()) {
|
|
return;
|
|
}
|
|
|
|
$images = array_map(function (string $filename): UploadedFile {
|
|
$path = public_path("images/tennants/onticket/onticket_tennant_hero_carousel/{$filename}");
|
|
|
|
if (! is_file($path)) {
|
|
throw new RuntimeException("Image not found at path: {$path}");
|
|
}
|
|
|
|
$mimeType = match (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
|
|
'jpg', 'jpeg', 'jfif' => 'image/jpeg',
|
|
'avif' => 'image/avif',
|
|
default => 'image/png',
|
|
};
|
|
|
|
return new UploadedFile($path, $filename, $mimeType, null, true);
|
|
}, self::IMAGES);
|
|
|
|
$this->websiteExtraService->updateForTenant($tenant, 'immersiveHeroCarousel', $images);
|
|
}
|
|
}
|