feat: implement full CRUD support and database schema for multi-tenant architecture

This commit is contained in:
2026-06-26 16:57:59 -03:00
parent 8708cea122
commit 31b65eb676
10 changed files with 562 additions and 58 deletions

View File

@@ -27,33 +27,40 @@ class TenantService
unset($data['header_logo'], $data['footer_logo']);
/** @var Tenant $tenant */
$tenant = Tenant::query()->create($data);
$headerAttachmentId = null;
if ($headerLogo) {
$attachment = Str::isUuid($headerLogo)
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $headerLogo)->first()
: $this->attachmentService->store($headerLogo, 'tenants');
if ($attachment) {
$tenant->header_logo_id = $attachment->id;
$tenant->attachments()->attach($attachment->id);
$headerAttachmentId = $attachment->id;
}
}
$footerAttachmentId = null;
if ($footerLogo) {
$attachment = Str::isUuid($footerLogo)
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $footerLogo)->first()
: $this->attachmentService->store($footerLogo, 'tenants');
if ($attachment) {
$tenant->footer_logo_id = $attachment->id;
$tenant->attachments()->attach($attachment->id);
$footerAttachmentId = $attachment->id;
}
}
if ($headerLogo || $footerLogo) {
$tenant->save();
$data['header_logo_id'] = $headerAttachmentId;
$data['footer_logo_id'] = $footerAttachmentId;
/** @var Tenant $tenant */
$tenant = Tenant::query()->create($data);
if ($headerAttachmentId) {
$tenant->attachments()->attach($headerAttachmentId);
}
if ($footerAttachmentId) {
$tenant->attachments()->attach($footerAttachmentId);
}
return $tenant;