Skip to content

Commit a37e651

Browse files
committed
Merge branch 'main' into feat/form-layout-components
2 parents ba61ff4 + 95464a3 commit a37e651

37 files changed

+2080
-1608
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v5
17+
uses: actions/checkout@v6
1818
with:
1919
ref: ${{ github.head_ref }}
2020

2121
- name: Fix PHP code style issues
2222
uses: aglipanci/[email protected]
2323

2424
- name: Commit changes
25-
uses: stefanzweifel/git-auto-commit-action@v6
25+
uses: stefanzweifel/git-auto-commit-action@v7
2626
with:
27-
commit_message: Fix styling
27+
commit_message: "styles: fix styling issues"

.github/workflows/phpstan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
name: phpstan
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5
14+
- uses: actions/checkout@v6
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: '8.2'
19+
php-version: '8.3'
2020
coverage: none
2121

2222
- name: Install composer dependencies

.github/workflows/run-tests.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.3, 8.2]
17-
laravel: [11.*]
18-
stability: [prefer-lowest, prefer-stable]
16+
php: [8.3]
17+
laravel: [12.*]
1918
include:
20-
- laravel: 11.*
21-
testbench: 9.*
22-
carbon: ^2.72.2
23-
exclude:
24-
- laravel: 11.*
25-
php: 8.1
19+
- laravel: 12.*
20+
testbench: 10.*
21+
carbon: 3.*
2622

27-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
23+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}
2824

2925
steps:
3026
- name: Checkout code
31-
uses: actions/checkout@v5
27+
uses: actions/checkout@v6
3228

3329
- name: Setup PHP
3430
uses: shivammathur/setup-php@v2
@@ -45,10 +41,10 @@ jobs:
4541
- name: Install dependencies
4642
run: |
4743
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
48-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
44+
composer update --prefer-dist --no-interaction
4945
5046
- name: List Installed Dependencies
5147
run: composer show -D
5248

5349
- name: Execute tests
54-
run: vendor/bin/pest --ci
50+
run: vendor/bin/pest --ci --no-coverage

.github/workflows/update-changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v5
16+
uses: actions/checkout@v6
1717
with:
1818
ref: main
1919

@@ -24,7 +24,7 @@ jobs:
2424
release-notes: ${{ github.event.release.body }}
2525

2626
- name: Commit updated CHANGELOG
27-
uses: stefanzweifel/git-auto-commit-action@v6
27+
uses: stefanzweifel/git-auto-commit-action@v7
2828
with:
2929
branch: main
3030
commit_message: Update CHANGELOG

README.md

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ return [
8383
'selectable_resources' => [
8484
// App\Filament\Resources\ContentResource::class,
8585
],
86+
87+
// Models that can be used for visibility rules
88+
'visibility_models' => [
89+
// \App\Models\Content::class,
90+
// Add any models you want to use in visibility conditions
91+
],
8692
];
8793
```
8894

@@ -164,13 +170,113 @@ When no other fields are available for dependency rules, the field selection wil
164170

165171
#### Visibility Rules
166172

167-
Control when fields are shown or hidden based on conditions:
173+
Control when fields are shown or hidden based on conditions. The visibility system supports two types of conditions:
174+
175+
##### Field-Based Conditions
176+
177+
Show/hide fields based on other field values in the same form:
178+
179+
- **Field Selection**: Choose from available fields in the current form
180+
- **Dynamic Options**: Field options update automatically based on available fields
181+
- **Self-Exclusion**: Fields cannot reference themselves to prevent infinite loops
182+
183+
##### Model Attribute Conditions
168184

169-
- **Conditional Display**: Show/hide fields based on other field values
170-
- **Dynamic Forms**: Create adaptive forms that change based on user input
171-
- **Complex Logic**: Support for multiple conditions and logical operators
185+
Show/hide fields based on properties of the current record:
172186

173-
The visibility system works seamlessly with validation rules to create intelligent, user-friendly forms.
187+
- **Record Properties**: Access any attribute of the current model instance
188+
- **Model Selection**: Choose from configured models in your application
189+
- **Attribute Discovery**: Automatically discover available attributes from database schema
190+
191+
##### Configuration
192+
193+
To enable model attribute conditions, add your models to the `visibility_models` config array:
194+
195+
```php
196+
return [
197+
// ... other config
198+
199+
// Models that can be used for visibility rules
200+
'visibility_models' => [
201+
// \App\Models\Content::class,
202+
],
203+
];
204+
```
205+
206+
##### Supported Operators
207+
208+
The visibility system supports a comprehensive set of comparison operators:
209+
210+
- **Equality**: `equals`, `not_equals`
211+
- **Text Operations**: `contains`, `not_contains`, `starts_with`, `ends_with`
212+
- **Empty Checks**: `is_empty`, `is_not_empty`
213+
- **Numeric Comparisons**: `greater_than`, `less_than`, `greater_than_or_equal`, `less_than_or_equal`
214+
- **List Operations**: `in`, `not_in` (comma-separated values)
215+
216+
##### Logical Operators
217+
218+
Combine multiple conditions with logical operators:
219+
220+
- **AND Logic**: All conditions must be met for the field to be visible
221+
- **OR Logic**: Any condition can be met for the field to be visible
222+
223+
##### Example Use Cases
224+
225+
**Content Type-Based Fields**:
226+
```json
227+
{
228+
"logic": "AND",
229+
"conditions": [
230+
{
231+
"source": "model_attribute",
232+
"model": "App\\Models\\Content",
233+
"property": "type_slug",
234+
"operator": "equals",
235+
"value": "article"
236+
}
237+
]
238+
}
239+
```
240+
241+
**Multi-Condition Logic**:
242+
```json
243+
{
244+
"logic": "OR",
245+
"conditions": [
246+
{
247+
"source": "model_attribute",
248+
"model": "App\\Models\\Content",
249+
"property": "status",
250+
"operator": "equals",
251+
"value": "published"
252+
},
253+
{
254+
"source": "field",
255+
"property": "field_ulid_here",
256+
"operator": "equals",
257+
"value": "draft"
258+
}
259+
]
260+
}
261+
```
262+
263+
**Hide on Specific Pages**:
264+
```json
265+
{
266+
"logic": "AND",
267+
"conditions": [
268+
{
269+
"source": "model_attribute",
270+
"model": "App\\Models\\Content",
271+
"property": "slug",
272+
"operator": "not_equals",
273+
"value": "home"
274+
}
275+
]
276+
}
277+
```
278+
279+
The visibility system works seamlessly with validation rules to create intelligent, user-friendly forms that adapt to your data and user interactions.
174280

175281
### Making a resource page configurable
176282

@@ -382,6 +488,10 @@ The package includes a powerful Rich Editor with custom plugins:
382488

383489
- **[Jump Anchor Plugin](docs/jump-anchor-plugin.md)** - Add anchor links to selected text for navigation and jumping to specific sections
384490

491+
### Field Configuration
492+
493+
- **[Visibility Rules](docs/visibility-rules.md)** - Comprehensive guide to controlling field visibility based on conditions and record properties
494+
385495
## Testing
386496

387497
```bash

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^8.2",
23+
"php": "^8.3",
2424
"baspa/laravel-timezones": "^1.2",
2525
"filament/filament": "^4.0",
2626
"saade/filament-adjacency-list": "^4.0",
@@ -32,9 +32,9 @@
3232
"nunomaduro/collision": "^8.1.1||^7.10.0",
3333
"nunomaduro/larastan": "^3.0",
3434
"orchestra/testbench": "^9.0.0",
35-
"pestphp/pest": "^2.34",
36-
"pestphp/pest-plugin-arch": "^2.0",
37-
"pestphp/pest-plugin-laravel": "^2.0",
35+
"pestphp/pest": "^4.1",
36+
"pestphp/pest-plugin-arch": "^4.0",
37+
"pestphp/pest-plugin-laravel": "^4.0",
3838
"phpstan/extension-installer": "^1.1",
3939
"phpstan/phpstan-deprecation-rules": "^2.0",
4040
"phpstan/phpstan-phpunit": "^2.0"
@@ -74,8 +74,6 @@
7474
}
7575
}
7676
},
77-
"repositories": {
78-
},
7977
"minimum-stability": "beta",
8078
"prefer-stable": true
8179
}

config/backstage/fields.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
'selectable_resources' => [
2222
// App\Filament\Resources\ContentResource::class,
2323
],
24+
25+
// Models that can be used for visibility rules
26+
'visibility_models' => [
27+
// \App\Models\Content::class,
28+
],
2429
];
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Facades\DB;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
// Get all fields with config containing optionType
16+
$fields = DB::table('fields')
17+
->whereNotNull('config')
18+
->where('config', 'like', '%optionType%')
19+
->get();
20+
21+
foreach ($fields as $field) {
22+
$config = json_decode($field->config, true);
23+
24+
if (isset($config['optionType']) && is_string($config['optionType'])) {
25+
// Convert string to array format
26+
$config['optionType'] = [$config['optionType']];
27+
28+
// Update the field with the corrected config
29+
DB::table('fields')
30+
->where('ulid', $field->ulid)
31+
->update(['config' => json_encode($config)]);
32+
}
33+
}
34+
}
35+
36+
/**
37+
* Reverse the migrations.
38+
*/
39+
public function down(): void
40+
{
41+
// Get all fields with config containing optionType arrays
42+
$fields = DB::table('fields')
43+
->whereNotNull('config')
44+
->where('config', 'like', '%optionType%')
45+
->get();
46+
47+
foreach ($fields as $field) {
48+
$config = json_decode($field->config, true);
49+
50+
if (isset($config['optionType']) && is_array($config['optionType']) && count($config['optionType']) === 1) {
51+
// Convert array back to string format
52+
$config['optionType'] = $config['optionType'][0];
53+
54+
// Update the field with the reverted config
55+
DB::table('fields')
56+
->where('ulid', $field->ulid)
57+
->update(['config' => json_encode($config)]);
58+
}
59+
}
60+
}
61+
};

0 commit comments

Comments
 (0)