From 126d7c7f1ae905079919be9ec1444a6408377c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Mateusz=20Bro=C5=BCy=C5=84ski?= Date: Thu, 21 Nov 2024 11:54:00 +0100 Subject: [PATCH 1/2] MS w/ dynamic values for formbuilder --- .../1_docs/4_form-fields/06_multi-select.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/content/1_docs/4_form-fields/06_multi-select.md b/docs/content/1_docs/4_form-fields/06_multi-select.md index e71efe692..3a39fa0d9 100644 --- a/docs/content/1_docs/4_form-fields/06_multi-select.md +++ b/docs/content/1_docs/4_form-fields/06_multi-select.md @@ -208,13 +208,30 @@ public function afterSave($object, $fields) } ``` +:::tabs=currenttab.FormBuilder&items.FormBuilder|FormView::: +:::tab=name.FormBuilder::: + +```php + $form->add( + MultiSelect::make() + ->name('sectors') + ->options( + Options::fromArray(app()->make(SectorsRepository::class)->listAll()->toArray()) + ) + ); +``` + +:::#tab::: + +:::tab=name.FormView::: + - In your controller, add to the formData the collection of options: ```php protected function formData($request) { return [ - 'sectors' => app()->make(SectorRepository::class)->listAll() + 'sectors' => app()->make(SectorRepository::class)->listAll()->toArray() ]; } ``` @@ -229,6 +246,9 @@ protected function formData($request) /> ``` +:::#tab::: +:::#tabs::: + When used in a [block](../5_block-editor), no migration is needed. ## Multi Select Inline From 03d6d4c5421998fe339910a5891888d2e93fab0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Mateusz=20Bro=C5=BCy=C5=84ski?= Date: Thu, 21 Nov 2024 15:56:35 +0100 Subject: [PATCH 2/2] add :void to afterSave --- docs/content/1_docs/4_form-fields/06_multi-select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/1_docs/4_form-fields/06_multi-select.md b/docs/content/1_docs/4_form-fields/06_multi-select.md index 3a39fa0d9..1c8b1cf50 100644 --- a/docs/content/1_docs/4_form-fields/06_multi-select.md +++ b/docs/content/1_docs/4_form-fields/06_multi-select.md @@ -200,7 +200,7 @@ public function sectors() { - In your repository, make sure to sync the association when saving: ```php -public function afterSave($object, $fields) +public function afterSave($object, $fields): void { $object->sectors()->sync($fields['sectors'] ?? []);