Skip to content

Commit 6c014ec

Browse files
committed
Configurable tenancy key
1 parent c823c75 commit 6c014ec

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

config/filament-fields.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
'relationship' => 'tenant',
99

1010
// 'model' => \App\Models\Tenant::class,
11+
12+
// The key (id, ulid, uuid) to use for the tenant relationship
13+
'key' => 'id',
1114
],
1215

1316
'custom_fields' => [

database/migrations/create_fields_table.php.stub

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ return new class extends Migration
3030

3131
if (config('filament-fields.tenancy.is_tenant_aware')) {
3232
$tenant = config('filament-fields.tenancy.relationship');
33-
Schema::create('field_' . $tenant, function (Blueprint $table) use ($tenant) {
34-
$table->foreignUlid($tenant . '_ulid')->constrained(table: $tenant . '_table', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete();
33+
$key = config('filament-fields.tenancy.key');
34+
35+
Schema::create('field_' . $tenant, function (Blueprint $table) use ($tenant, $key) {
36+
$table->foreignUlid($tenant . '_' . $key)->constrained(table: $tenant, column: $key)->cascadeOnUpdate()->cascadeOnDelete();
3537
$table->foreignUlid('field_ulid')->constrained(table: 'fields_table', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete();
3638

37-
$table->index(['field_ulid', $tenant . '_ulid']);
39+
$table->index(['field_ulid', $tenant . '_' . $key]);
3840
});
3941
}
4042
}

0 commit comments

Comments
 (0)