Skip to content

Commit 09a35a5

Browse files
committed
refactor: use TenantContextService for tenant resolution
Replace direct Filament::getTenant() calls with TenantContextService for consistent tenant handling across management interfaces
1 parent 0aa6b5c commit 09a35a5

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/Filament/Management/Pages/CustomFieldsManagementPage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use BackedEnum;
88
use Filament\Actions\Action;
9-
use Filament\Facades\Filament;
9+
use Relaticle\CustomFields\Services\TenantContextService;
1010
use Filament\Pages\Page;
1111
use Filament\Panel;
1212
use Filament\Support\Enums\Size;
@@ -136,7 +136,7 @@ public function updateSectionsOrder(array $sections): void
136136
private function storeSection(array $data): CustomFieldSection
137137
{
138138
if (FeatureManager::isEnabled(CustomFieldsFeature::SYSTEM_MULTI_TENANCY)) {
139-
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = Filament::getTenant()?->getKey();
139+
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = TenantContextService::getCurrentTenantId();
140140
}
141141

142142
$data['type'] ??= CustomFieldSectionType::SECTION->value;

src/Filament/Management/Schemas/FieldForm.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Relaticle\CustomFields\Filament\Management\Schemas;
66

77
use Exception;
8+
use Relaticle\CustomFields\Services\TenantContextService;
89
use Filament\Forms\Components\ColorPicker;
910
use Filament\Forms\Components\Hidden;
1011
use Filament\Forms\Components\Repeater;
@@ -84,7 +85,7 @@ public static function schema(bool $withOptionsRelationship = true): array
8485
array $data
8586
): array {
8687
if (FeatureManager::isEnabled(CustomFieldsFeature::SYSTEM_MULTI_TENANCY)) {
87-
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = Filament::getTenant()?->getKey();
88+
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = TenantContextService::getCurrentTenantId();
8889
}
8990

9091
return $data;
@@ -175,7 +176,7 @@ public static function schema(bool $withOptionsRelationship = true): array
175176
config(
176177
'custom-fields.database.column_names.tenant_foreign_key'
177178
),
178-
Filament::getTenant()?->getKey()
179+
TenantContextService::getCurrentTenantId()
179180
)
180181
)
181182
)
@@ -235,7 +236,7 @@ public static function schema(bool $withOptionsRelationship = true): array
235236
config(
236237
'custom-fields.database.column_names.tenant_foreign_key'
237238
),
238-
Filament::getTenant()?->getKey()
239+
TenantContextService::getCurrentTenantId()
239240
)
240241
)
241242
)

src/Filament/Management/Schemas/SectionForm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Relaticle\CustomFields\Filament\Management\Schemas;
66

7-
use Filament\Facades\Filament;
7+
use Relaticle\CustomFields\Services\TenantContextService;
88
use Filament\Forms\Components\Select;
99
use Filament\Forms\Components\Textarea;
1010
use Filament\Forms\Components\TextInput;
@@ -55,7 +55,7 @@ public static function schema(): array
5555
config(
5656
'custom-fields.database.column_names.tenant_foreign_key'
5757
),
58-
Filament::getTenant()?->getKey()
58+
TenantContextService::getCurrentTenantId()
5959
)
6060
)
6161
->where('entity_type', self::$entityType)
@@ -97,7 +97,7 @@ public static function schema(): array
9797
config(
9898
'custom-fields.database.column_names.tenant_foreign_key'
9999
),
100-
Filament::getTenant()?->getKey()
100+
TenantContextService::getCurrentTenantId()
101101
)
102102
)
103103
->where('entity_type', self::$entityType)

src/Livewire/ManageCustomFieldSection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Filament\Actions\ActionGroup;
99
use Filament\Actions\Concerns\InteractsWithActions;
1010
use Filament\Actions\Contracts\HasActions;
11-
use Filament\Facades\Filament;
11+
use Relaticle\CustomFields\Services\TenantContextService;
1212
use Filament\Forms\Concerns\InteractsWithForms;
1313
use Filament\Forms\Contracts\HasForms;
1414
use Filament\Support\Enums\Size;
@@ -167,7 +167,7 @@ public function createFieldAction(): Action
167167
])
168168
->mutateDataUsing(function (array $data): array {
169169
if (FeatureManager::isEnabled(CustomFieldsFeature::SYSTEM_MULTI_TENANCY)) {
170-
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = Filament::getTenant()?->getKey();
170+
$data[config('custom-fields.database.column_names.tenant_foreign_key')] = TenantContextService::getCurrentTenantId();
171171
}
172172

173173
return [
@@ -181,7 +181,7 @@ public function createFieldAction(): Action
181181
->filter()
182182
->map(function (array $option): array {
183183
if (FeatureManager::isEnabled(CustomFieldsFeature::SYSTEM_MULTI_TENANCY)) {
184-
$option[config('custom-fields.database.column_names.tenant_foreign_key')] = Filament::getTenant()?->getKey();
184+
$option[config('custom-fields.database.column_names.tenant_foreign_key')] = TenantContextService::getCurrentTenantId();
185185
}
186186

187187
return $option;

0 commit comments

Comments
 (0)