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'), +``` 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]); } /**