feat: implement full CRUD support and database schema for multi-tenant architecture
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user