diff --git a/composer.lock b/composer.lock index 6ea2ccb7e5..6c2ce0286d 100644 --- a/composer.lock +++ b/composer.lock @@ -129,16 +129,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.299.1", + "version": "3.300.3", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "a0f87b8e8bfb9afd0ffd702fcda556b465eee457" + "reference": "a1202d1a82593fc2cdad54d627e54c518a984738" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/a0f87b8e8bfb9afd0ffd702fcda556b465eee457", - "reference": "a0f87b8e8bfb9afd0ffd702fcda556b465eee457", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/a1202d1a82593fc2cdad54d627e54c518a984738", + "reference": "a1202d1a82593fc2cdad54d627e54c518a984738", "shasum": "" }, "require": { @@ -218,9 +218,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.299.1" + "source": "https://github.com/aws/aws-sdk-php/tree/3.300.3" }, - "time": "2024-02-16T19:08:34+00:00" + "time": "2024-02-22T19:20:21+00:00" }, { "name": "blade-ui-kit/blade-heroicons", @@ -374,16 +374,16 @@ }, { "name": "brianium/paratest", - "version": "v7.4.1", + "version": "v7.4.3", "source": { "type": "git", "url": "https://github.com/paratestphp/paratest.git", - "reference": "b2830e330011d59a799c0002e118f5b4bbdb9604" + "reference": "64fcfd0e28a6b8078a19dbf9127be2ee645b92ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paratestphp/paratest/zipball/b2830e330011d59a799c0002e118f5b4bbdb9604", - "reference": "b2830e330011d59a799c0002e118f5b4bbdb9604", + "url": "https://api.github.com/repos/paratestphp/paratest/zipball/64fcfd0e28a6b8078a19dbf9127be2ee645b92ec", + "reference": "64fcfd0e28a6b8078a19dbf9127be2ee645b92ec", "shasum": "" }, "require": { @@ -391,13 +391,13 @@ "ext-pcre": "*", "ext-reflection": "*", "ext-simplexml": "*", - "fidry/cpu-core-counter": "^1.0.0", + "fidry/cpu-core-counter": "^1.1.0", "jean85/pretty-package-versions": "^2.0.5", "php": "~8.2.0 || ~8.3.0", "phpunit/php-code-coverage": "^10.1.11 || ^11.0.0", "phpunit/php-file-iterator": "^4.1.0 || ^5.0.0", "phpunit/php-timer": "^6.0.0 || ^7.0.0", - "phpunit/phpunit": "^10.5.9 || ^11.0.2", + "phpunit/phpunit": "^10.5.9 || ^11.0.3", "sebastian/environment": "^6.0.1 || ^7.0.0", "symfony/console": "^6.4.3 || ^7.0.3", "symfony/process": "^6.4.3 || ^7.0.3" @@ -406,11 +406,11 @@ "doctrine/coding-standard": "^12.0.0", "ext-pcov": "*", "ext-posix": "*", - "phpstan/phpstan": "^1.10.57", + "phpstan/phpstan": "^1.10.58", "phpstan/phpstan-deprecation-rules": "^1.1.4", "phpstan/phpstan-phpunit": "^1.3.15", "phpstan/phpstan-strict-rules": "^1.5.2", - "squizlabs/php_codesniffer": "^3.8.1", + "squizlabs/php_codesniffer": "^3.9.0", "symfony/filesystem": "^6.4.3 || ^7.0.3" }, "bin": [ @@ -452,7 +452,7 @@ ], "support": { "issues": "https://github.com/paratestphp/paratest/issues", - "source": "https://github.com/paratestphp/paratest/tree/v7.4.1" + "source": "https://github.com/paratestphp/paratest/tree/v7.4.3" }, "funding": [ { @@ -464,7 +464,7 @@ "type": "paypal" } ], - "time": "2024-02-06T13:50:28+00:00" + "time": "2024-02-20T07:24:02+00:00" }, { "name": "brick/math", @@ -1570,15 +1570,15 @@ "dist": { "type": "path", "url": "packages/support", - "reference": "70668ccdd8bce1e3df337ed3e483150a70207728" + "reference": "099ac9c8ddf7d2d6fdb9ccd8ed7d43782645bd4f" }, "require": { "blade-ui-kit/blade-heroicons": "^2.2.1", "doctrine/dbal": "^3.2", "ext-intl": "*", - "illuminate/contracts": "^10.0", - "illuminate/support": "^10.0", - "illuminate/view": "^10.0", + "illuminate/contracts": "^10.45", + "illuminate/support": "^10.45", + "illuminate/view": "^10.45", "livewire/livewire": "^3.2.3", "php": "^8.1", "ryangjchandler/blade-capture-directive": "^0.2|^0.3", @@ -2593,16 +2593,16 @@ }, { "name": "laravel/framework", - "version": "v10.44.0", + "version": "v10.45.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "1199dbe361787bbe9648131a79f53921b4148cf6" + "reference": "dcf5d1d722b84ad38a5e053289130b6962f830bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/1199dbe361787bbe9648131a79f53921b4148cf6", - "reference": "1199dbe361787bbe9648131a79f53921b4148cf6", + "url": "https://api.github.com/repos/laravel/framework/zipball/dcf5d1d722b84ad38a5e053289130b6962f830bd", + "reference": "dcf5d1d722b84ad38a5e053289130b6962f830bd", "shasum": "" }, "require": { @@ -2795,20 +2795,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-02-13T16:01:16+00:00" + "time": "2024-02-21T14:07:36+00:00" }, { "name": "laravel/pint", - "version": "v1.13.11", + "version": "v1.14.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552" + "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/60a163c3e7e3346a1dec96d3e6f02e6465452552", - "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552", + "url": "https://api.github.com/repos/laravel/pint/zipball/6b127276e3f263f7bb17d5077e9e0269e61b2a0e", + "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e", "shasum": "" }, "require": { @@ -2861,7 +2861,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-02-13T17:20:13+00:00" + "time": "2024-02-20T17:38:05+00:00" }, { "name": "laravel/prompts", @@ -3236,16 +3236,16 @@ }, { "name": "league/csv", - "version": "9.14.0", + "version": "9.15.0", "source": { "type": "git", "url": "https://github.com/thephpleague/csv.git", - "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5" + "reference": "fa7e2441c0bc9b2360f4314fd6c954f7ff40d435" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/csv/zipball/34bf0df7340b60824b9449b5c526fcc3325070d5", - "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/fa7e2441c0bc9b2360f4314fd6c954f7ff40d435", + "reference": "fa7e2441c0bc9b2360f4314fd6c954f7ff40d435", "shasum": "" }, "require": { @@ -3260,12 +3260,12 @@ "ext-xdebug": "*", "friendsofphp/php-cs-fixer": "^v3.22.0", "phpbench/phpbench": "^1.2.15", - "phpstan/phpstan": "^1.10.50", + "phpstan/phpstan": "^1.10.57", "phpstan/phpstan-deprecation-rules": "^1.1.4", "phpstan/phpstan-phpunit": "^1.3.15", "phpstan/phpstan-strict-rules": "^1.5.2", - "phpunit/phpunit": "^10.5.3", - "symfony/var-dumper": "^6.4.0" + "phpunit/phpunit": "^10.5.9", + "symfony/var-dumper": "^6.4.2" }, "suggest": { "ext-dom": "Required to use the XMLConverter and the HTMLConverter classes", @@ -3321,7 +3321,7 @@ "type": "github" } ], - "time": "2023-12-29T07:34:53+00:00" + "time": "2024-02-20T20:00:00+00:00" }, { "name": "league/flysystem", @@ -3770,16 +3770,16 @@ }, { "name": "livewire/livewire", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "c0489d4a76382f6dcf6e2702112f86aa089d0c8d" + "reference": "7e7d638183b34fb61621455891869f5abfd55a82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/c0489d4a76382f6dcf6e2702112f86aa089d0c8d", - "reference": "c0489d4a76382f6dcf6e2702112f86aa089d0c8d", + "url": "https://api.github.com/repos/livewire/livewire/zipball/7e7d638183b34fb61621455891869f5abfd55a82", + "reference": "7e7d638183b34fb61621455891869f5abfd55a82", "shasum": "" }, "require": { @@ -3833,7 +3833,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v3.4.4" + "source": "https://github.com/livewire/livewire/tree/v3.4.6" }, "funding": [ { @@ -3841,7 +3841,7 @@ "type": "github" } ], - "time": "2024-01-28T19:07:11+00:00" + "time": "2024-02-20T14:04:25+00:00" }, { "name": "maennchen/zipstream-php", @@ -4645,16 +4645,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.0.0", + "version": "v5.0.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc" + "reference": "2218c2252c874a4624ab2f613d86ac32d227bc69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4a21235f7e56e713259a6f76bf4b5ea08502b9dc", - "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/2218c2252c874a4624ab2f613d86ac32d227bc69", + "reference": "2218c2252c874a4624ab2f613d86ac32d227bc69", "shasum": "" }, "require": { @@ -4697,9 +4697,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.1" }, - "time": "2024-01-07T17:17:35+00:00" + "time": "2024-02-21T19:24:10+00:00" }, { "name": "nunomaduro/collision", @@ -5180,16 +5180,16 @@ }, { "name": "orchestra/testbench-core", - "version": "v8.21.1", + "version": "v8.22.1", "source": { "type": "git", "url": "https://github.com/orchestral/testbench-core.git", - "reference": "c6bf49a1b7ef4afe58e5bda676158c4de41f9a81" + "reference": "b0006c092694828f4b0fa409a369b798e5e26f8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/c6bf49a1b7ef4afe58e5bda676158c4de41f9a81", - "reference": "c6bf49a1b7ef4afe58e5bda676158c4de41f9a81", + "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/b0006c092694828f4b0fa409a369b798e5e26f8d", + "reference": "b0006c092694828f4b0fa409a369b798e5e26f8d", "shasum": "" }, "require": { @@ -5268,7 +5268,7 @@ "issues": "https://github.com/orchestral/testbench/issues", "source": "https://github.com/orchestral/testbench-core" }, - "time": "2024-01-22T01:45:47+00:00" + "time": "2024-02-21T23:33:22+00:00" }, { "name": "orchestra/workbench", @@ -5886,21 +5886,21 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.8.0", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fad452781b3d774e3337b0c0b245dd8e5a4455fc", - "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -5938,9 +5938,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2024-01-11T11:49:22+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpmyadmin/sql-parser", @@ -8930,16 +8930,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "11.4.1", + "version": "11.4.4", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "d94b110c2ee9a0602ae1be9bf59e91ae8dab28cf" + "reference": "bb29cacfe209856db304adc6c5ba8c05ff7a8802" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/d94b110c2ee9a0602ae1be9bf59e91ae8dab28cf", - "reference": "d94b110c2ee9a0602ae1be9bf59e91ae8dab28cf", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/bb29cacfe209856db304adc6c5ba8c05ff7a8802", + "reference": "bb29cacfe209856db304adc6c5ba8c05ff7a8802", "shasum": "" }, "require": { @@ -9022,7 +9022,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-medialibrary/issues", - "source": "https://github.com/spatie/laravel-medialibrary/tree/11.4.1" + "source": "https://github.com/spatie/laravel-medialibrary/tree/11.4.4" }, "funding": [ { @@ -9034,7 +9034,7 @@ "type": "github" } ], - "time": "2024-02-17T12:22:37+00:00" + "time": "2024-02-22T09:39:31+00:00" }, { "name": "spatie/laravel-package-tools", @@ -9183,20 +9183,20 @@ }, { "name": "spatie/laravel-tags", - "version": "4.5.2", + "version": "4.6.0", "source": { "type": "git", "url": "https://github.com/spatie/laravel-tags.git", - "reference": "627587878731650c52d79e2132cfd1410a18d428" + "reference": "ddcc82e1149c4720c0eaa02d171f50a1cdd1cb46" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-tags/zipball/627587878731650c52d79e2132cfd1410a18d428", - "reference": "627587878731650c52d79e2132cfd1410a18d428", + "url": "https://api.github.com/repos/spatie/laravel-tags/zipball/ddcc82e1149c4720c0eaa02d171f50a1cdd1cb46", + "reference": "ddcc82e1149c4720c0eaa02d171f50a1cdd1cb46", "shasum": "" }, "require": { - "laravel/framework": "^8.67|^9.0|^10.0", + "laravel/framework": "^8.67|^9.0|^10.0|^11.0", "nesbot/carbon": "^2.63", "php": "^8.0", "spatie/eloquent-sortable": "^3.10|^4.0", @@ -9204,8 +9204,8 @@ "spatie/laravel-translatable": "^4.6|^5.0|^6.0" }, "require-dev": { - "orchestra/testbench": "^6.13|^7.0|^8.0", - "pestphp/pest": "^1.22", + "orchestra/testbench": "^6.13|^7.0|^8.0|^9.0", + "pestphp/pest": "^1.22|^2.0", "phpunit/phpunit": "^9.5.2" }, "type": "library", @@ -9241,7 +9241,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-tags/issues", - "source": "https://github.com/spatie/laravel-tags/tree/4.5.2" + "source": "https://github.com/spatie/laravel-tags/tree/4.6.0" }, "funding": [ { @@ -9249,7 +9249,7 @@ "type": "github" } ], - "time": "2024-01-19T22:10:13+00:00" + "time": "2024-02-21T12:13:18+00:00" }, { "name": "spatie/laravel-translatable", diff --git a/packages/forms/docs/03-fields/03-select.md b/packages/forms/docs/03-fields/03-select.md index f64aa14eec..1da5a36f40 100644 --- a/packages/forms/docs/03-fields/03-select.md +++ b/packages/forms/docs/03-fields/03-select.md @@ -264,6 +264,21 @@ Select::make('author_id') ->searchable(['first_name', 'last_name']) ``` +### Saving pivot data to the relationship + +If you're using a `multiple()` relationship and your pivot table has additional columns, you can use the `pivotData()` method to specify the data that should be saved in them: + +```php +use Filament\Forms\Components\Select; + +Select::make('primaryTechnologies') + ->relationship(name: 'technologies', titleAttribute: 'name') + ->multiple() + ->pivotData([ + 'is_primary' => true, + ]) +``` + ### Creating a new option in a modal You may define a custom form that can be used to create a new record and attach it to the `BelongsTo` relationship: diff --git a/packages/forms/docs/03-fields/06-checkbox-list.md b/packages/forms/docs/03-fields/06-checkbox-list.md index 0969434b9a..c6155c4983 100644 --- a/packages/forms/docs/03-fields/06-checkbox-list.md +++ b/packages/forms/docs/03-fields/06-checkbox-list.md @@ -240,6 +240,20 @@ CheckboxList::make('authors') ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->first_name} {$record->last_name}") ``` +### Saving pivot data to the relationship + +If your pivot table has additional columns, you can use the `pivotData()` method to specify the data that should be saved in them: + +```php +use Filament\Forms\Components\CheckboxList; + +CheckboxList::make('primaryTechnologies') + ->relationship(name: 'technologies', titleAttribute: 'name') + ->pivotData([ + 'is_primary' => true, + ]) +``` + ## Setting a custom no search results message When you're using a searchable checkbox list, you may want to display a custom message when no search results are found. You can do this using the `noSearchResultsMessage()` method: diff --git a/packages/forms/src/Components/CheckboxList.php b/packages/forms/src/Components/CheckboxList.php index 28db14e1dc..fc9576fb8b 100644 --- a/packages/forms/src/Components/CheckboxList.php +++ b/packages/forms/src/Components/CheckboxList.php @@ -24,6 +24,7 @@ class CheckboxList extends Field implements Contracts\CanDisableOptions, Contrac use Concerns\HasGridDirection; use Concerns\HasNestedRecursiveValidationRules; use Concerns\HasOptions; + use Concerns\HasPivotData; /** * @var view-string @@ -185,7 +186,15 @@ class CheckboxList extends Field implements Contracts\CanDisableOptions, Contrac }); $this->saveRelationshipsUsing(static function (CheckboxList $component, ?array $state) { - $component->getRelationship()->sync($state ?? []); + $pivotData = $component->getPivotData(); + + if ($pivotData === []) { + $component->getRelationship()->sync($state ?? []); + + return; + } + + $component->getRelationship()->syncWithPivotValues($state ?? [], $pivotData); }); $this->dehydrated(false); diff --git a/packages/forms/src/Components/Concerns/HasPivotData.php b/packages/forms/src/Components/Concerns/HasPivotData.php new file mode 100644 index 0000000000..ea4b817171 --- /dev/null +++ b/packages/forms/src/Components/Concerns/HasPivotData.php @@ -0,0 +1,31 @@ + | Closure + */ + protected array | Closure $pivotData = []; + + /** + * @param array | Closure $data + */ + public function pivotData(array | Closure $data): static + { + $this->pivotData = $data; + + return $this; + } + + /** + * @return array + */ + public function getPivotData(): array + { + return $this->evaluate($this->pivotData) ?? []; + } +} diff --git a/packages/forms/src/Components/Select.php b/packages/forms/src/Components/Select.php index d196f28e7a..ebed92312e 100644 --- a/packages/forms/src/Components/Select.php +++ b/packages/forms/src/Components/Select.php @@ -46,6 +46,7 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has use Concerns\HasLoadingMessage; use Concerns\HasNestedRecursiveValidationRules; use Concerns\HasOptions; + use Concerns\HasPivotData; use Concerns\HasPlaceholder; use HasExtraAlpineAttributes; @@ -963,7 +964,15 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has return; } - $relationship->sync($state ?? []); + $pivotData = $component->getPivotData(); + + if ($pivotData === []) { + $relationship->sync($state ?? []); + + return; + } + + $relationship->syncWithPivotValues($state ?? [], $pivotData); }); $this->createOptionUsing(static function (Select $component, array $data, Form $form) {