feat(website-type): add presentation fields and site logo relationship to WebsiteType model

This commit is contained in:
2026-07-31 11:39:17 -03:00
parent cf2beb2ff5
commit 3968a10f6a
6 changed files with 135 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ class TenantInformationService
'headerLogo',
'footerLogo',
'socialMedia',
'websiteType',
'websiteType.siteLogo',
'websiteExtras.websiteTypeExtra',
];

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Domains\Tenant\Services;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Attachable\Services\AttachmentService;
use App\Domains\Tenant\Models\WebsiteType;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class WebsiteTypeService
{
public function __construct(
protected AttachmentService $attachmentService,
) {}
/**
* Create a website type and store its site logo.
*
* @param array<string, mixed> $data
*/
public function create(array $data): WebsiteType
{
return DB::transaction(function () use ($data): WebsiteType {
$siteLogo = $data['site_logo'] ?? null;
unset($data['site_logo']);
$siteLogoAttachmentId = null;
if ($siteLogo) {
$attachment = Str::isUuid($siteLogo)
? Attachment::query()->where('key', $siteLogo)->first()
: $this->attachmentService->store($siteLogo, 'website-types');
if ($attachment) {
$siteLogoAttachmentId = $attachment->id;
}
}
$data['site_logo'] = $siteLogoAttachmentId;
/** @var WebsiteType $websiteType */
$websiteType = WebsiteType::query()->create($data);
return $websiteType;
});
}
}