Skip to content

Commit c823c75

Browse files
committed
Update config
1 parent 6cb7fde commit c823c75

File tree

6 files changed

+57
-32
lines changed

6 files changed

+57
-32
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,33 @@ You should publish the config file first with:
5555
php artisan vendor:publish --tag="filament-fields-config"
5656
```
5757

58-
This will create a `fields.php` file in your `config` directory. Make sure to fill in the tenant relationship and the tenant model (if you're using multi-tenancy). When running the migrations, the fields table will be created with the correct tenant relationship.
58+
This will create a `filament-fields.php` file in your `config` directory. Make sure to fill in the tenant relationship and the tenant model (if you're using multi-tenancy). When running the migrations, the fields table will be created with the correct tenant relationship.
59+
60+
The content of the `filament-fields.php` file is as follows:
61+
62+
```php
63+
<?php
64+
65+
return [
66+
67+
'tenancy' => [
68+
'is_tenant_aware' => true,
69+
70+
'relationship' => 'tenant',
71+
72+
// 'model' => \App\Models\Tenant::class,
73+
],
74+
75+
'custom_fields' => [
76+
// App\Fields\CustomField::class,
77+
],
78+
79+
// When populating the select field, this will be used to build the relationship options.
80+
'selectable_resources' => [
81+
// App\Filament\Resources\ContentResource::class,
82+
],
83+
];
84+
```
5985

6086
You can publish and run the migrations with:
6187

@@ -137,7 +163,7 @@ class EditSetting extends EditRecord
137163

138164
### Add resources as options for select fields
139165

140-
To add resources as options for select fields, you can add them to the `filament-fields.select.resource_options` config array.
166+
To add resources as options for select fields, you can add them to the `filament-fields.selectable_resources` config array.
141167

142168
```php
143169
return [
@@ -160,7 +186,7 @@ return [
160186
To register your own fields, you can add them to the `filament-fields.fields` config array.
161187

162188
```php
163-
'fields' => [
189+
'custom_fields' => [
164190
App\Fields\CustomField::class,
165191
],
166192
```

config/filament-fields.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
return [
44

5-
'is_tenant_aware' => true,
5+
'tenancy' => [
6+
'is_tenant_aware' => true,
67

7-
'tenant_ownership_relationship_name' => 'tenant',
8+
'relationship' => 'tenant',
89

9-
'tenant_relationship' => 'tenant',
10-
11-
// 'tenant_model' => \App\Models\Tenant::class,
10+
// 'model' => \App\Models\Tenant::class,
11+
],
1212

13-
'fields' => [
13+
'custom_fields' => [
1414
// App\Fields\CustomField::class,
1515
],
1616

17-
'select' => [
18-
'resource_options' => [
19-
// App\Filament\Resources\ContentResource::class,
20-
],
17+
// When populating the select field, this will be used to build the relationship options.
18+
'selectable_resources' => [
19+
// App\Filament\Resources\ContentResource::class,
2120
],
22-
];
21+
];

database/migrations/create_fields_table.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ return new class extends Migration
2828
$table->unique(['model_type', 'model_key', 'slug']);
2929
});
3030

31-
if (config('fields.is_tenant_aware')) {
32-
$tenant = config('fields.tenant_relationship');
31+
if (config('filament-fields.tenancy.is_tenant_aware')) {
32+
$tenant = config('filament-fields.tenancy.relationship');
3333
Schema::create('field_' . $tenant, function (Blueprint $table) use ($tenant) {
3434
$table->foreignUlid($tenant . '_ulid')->constrained(table: $tenant . '_table', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete();
3535
$table->foreignUlid('field_ulid')->constrained(table: 'fields_table', column: 'ulid')->cascadeOnUpdate()->cascadeOnDelete();

src/Concerns/HasOptions.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function addOptionsToInput(mixed $input, mixed $field): mixed
1717
$options = [];
1818

1919
foreach ($field->config['relations'] as $relation) {
20-
$resources = config('filament-fields.select.resource_options');
20+
$resources = config('filament-fields.selectable_resources');
2121
$resourceClass = collect($resources)->first(function ($resource) use ($relation) {
2222
$res = new $resource;
2323
$model = $res->getModel();
@@ -105,8 +105,8 @@ public function optionFormFields(): Fieldset
105105
Forms\Components\KeyValue::make('config.options')
106106
->label(__('Options'))
107107
->columnSpanFull()
108-
->visible(fn (Forms\Get $get): bool => $get('config.optionType') == 'array')
109-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'array'),
108+
->visible(fn(Forms\Get $get): bool => $get('config.optionType') == 'array')
109+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'array'),
110110
// Relationship options
111111
Repeater::make('config.relations')
112112
->label(__('Relations'))
@@ -121,7 +121,7 @@ public function optionFormFields(): Fieldset
121121
->columnSpanFull()
122122
->live(debounce: 250)
123123
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
124-
$resources = config('filament-fields.select.resource_options');
124+
$resources = config('filament-fields.selectable_resources');
125125
$resourceClass = collect($resources)->first(function ($resource) use ($state) {
126126
$res = new $resource;
127127
$model = $res->getModel();
@@ -150,7 +150,7 @@ public function optionFormFields(): Fieldset
150150
$set('relationValue_options', $columnOptions);
151151
})
152152
->options(function () {
153-
$resources = config('filament-fields.select.resource_options');
153+
$resources = config('filament-fields.selectable_resources');
154154

155155
return collect($resources)->map(function ($resource) {
156156
$res = new $resource;
@@ -165,19 +165,19 @@ public function optionFormFields(): Fieldset
165165
->toArray();
166166
})
167167
->noSearchResultsMessage(__('No types found'))
168-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
168+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
169169
Forms\Components\Hidden::make('relationKey')
170170
->default('ulid')
171171
->label(__('Key'))
172-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
172+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
173173
Forms\Components\Repeater::make('relationValue_filters')
174174
->label(__('Filters'))
175-
->visible(fn (Forms\Get $get): bool => ! empty($get('resource')))
175+
->visible(fn(Forms\Get $get): bool => ! empty($get('resource')))
176176
->schema([
177177
Forms\Components\Grid::make(3)
178178
->schema([
179179
Forms\Components\Select::make('column')
180-
->options(fn (\Filament\Forms\Get $get) => $get('../../relationValue_options') ?? [
180+
->options(fn(\Filament\Forms\Get $get) => $get('../../relationValue_options') ?? [
181181
'slug' => __('Slug'),
182182
'name' => __('Name'),
183183
])
@@ -204,7 +204,7 @@ public function optionFormFields(): Fieldset
204204
return [];
205205
}
206206

207-
$resources = config('filament-fields.select.resource_options');
207+
$resources = config('filament-fields.selectable_resources');
208208
$resourceClass = collect($resources)->first(function ($r) use ($resource) {
209209
$res = new $r;
210210
$model = $res->getModel();
@@ -232,7 +232,7 @@ public function optionFormFields(): Fieldset
232232
->columnSpanFull(),
233233
]),
234234
])
235-
->visible(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship')
235+
->visible(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship')
236236
->columnSpanFull(),
237237
]),
238238
]);

src/FieldsServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function packageBooted(): void
9191

9292
$this->app->bind(FieldInspector::class, FieldInspectionService::class);
9393

94-
collect($this->app['config']['filament-fields']['fields'] ?? [])
94+
collect($this->app['config']['filament-fields']['custom_fields'] ?? [])
9595
->each(function ($field) {
9696
Fields::registerField($field);
9797
});
@@ -155,4 +155,4 @@ protected function getMigrations(): array
155155
'create_fields_table',
156156
];
157157
}
158-
}
158+
}

src/Models/Field.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public function children(): HasMany
4040

4141
public function tenant(): ?BelongsTo
4242
{
43-
$tenantRelationship = Config::get('fields.tenant_relationship');
44-
$tenantModel = Config::get('fields.tenant_model');
43+
$tenantRelationship = Config::get('filament-fields.tenancy.relationship');
44+
$tenantModel = Config::get('filament-fields.tenancy.model');
4545

4646
if ($tenantRelationship && class_exists($tenantModel)) {
4747
return $this->belongsTo($tenantModel, $tenantRelationship . '_ulid');
4848
}
4949

5050
return null;
5151
}
52-
}
52+
}

0 commit comments

Comments
 (0)