From 3f5e251265e1026df6acb1588643bb8f5f3576f7 Mon Sep 17 00:00:00 2001 From: smskin Date: Wed, 12 Jan 2022 19:12:41 +0300 Subject: [PATCH 1/2] added label panel property for customize --- src/NestedForm.php | 15 +++++++++++---- src/NestedFormPanel.php | 8 ++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/NestedForm.php b/src/NestedForm.php index b572c6a..ded2c4b 100644 --- a/src/NestedForm.php +++ b/src/NestedForm.php @@ -173,15 +173,21 @@ class NestedForm extends Field implements RelatableField */ protected $returnContext; + /** + * @var string|null + */ + public $panelLabel; + /** * Create a new nested form. * - * @param string $name - * @param string|null $attribute - * @param string|null $resource + * @param string $name + * @param string|null $attribute + * @param string|null $resource + * @param string|null $panelLabel * @return void */ - public function __construct(string $name, $attribute = null, $resource = null) + public function __construct(string $name, $attribute = null, $resource = null, $panelLabel = null) { parent::__construct($name, $attribute); @@ -195,6 +201,7 @@ public function __construct(string $name, $attribute = null, $resource = null) $this->keyName = (new $this->resourceClass::$model)->getKeyName(); $this->viaResource = app(NovaRequest::class)->route('resource'); $this->returnContext = $this; + $this->panelLabel = $panelLabel; // Nova ^3.3.x need this to fix cannot add relation on create mode $this->resolve(app(NovaRequest::class)->model()); diff --git a/src/NestedFormPanel.php b/src/NestedFormPanel.php index 8de2316..e00d996 100644 --- a/src/NestedFormPanel.php +++ b/src/NestedFormPanel.php @@ -8,7 +8,7 @@ class NestedFormPanel extends Panel { /** * Nested form. - * + * * @var NestedForm */ protected $nestedForm; @@ -22,7 +22,11 @@ public function __construct(NestedForm $nestedForm) $this->nestedForm->asPanel($this); - parent::__construct(__('Update Related :resource', ['resource' => $this->nestedForm->name]), [$this->nestedForm]); + if (!$nestedForm->panelLabel) { + $nestedForm->panelLabel = __('Update Related :resource', ['resource' => $this->nestedForm->name]); + } + + parent::__construct($nestedForm->panelLabel, [$this->nestedForm]); } /** From 1fc5f5720dc761500d2a4038fe1ce9f2edc5ef12 Mon Sep 17 00:00:00 2001 From: smskin Date: Sun, 1 May 2022 00:27:07 +0300 Subject: [PATCH 2/2] changed the readme file --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 5f3395a..526e865 100644 --- a/README.md +++ b/README.md @@ -169,3 +169,11 @@ You can modify the default index separator using the separator() method when you ```php NestedForm::make('Posts')->separator('\'), ``` + +# Modify default label of panel + +You can modify default label of panel (Update Related :resource) to any custom. Pass name of label as the fourth argument of the constructor. + +```php +NestedForm::make('Posts', 'posts', Post::class, 'Custom label of the panel'), +```