From dfbc79a70291e4d367241a90bc2d7ee3f7e2e7a6 Mon Sep 17 00:00:00 2001 From: Dmytro Kulyk Date: Wed, 23 Jan 2019 12:54:23 +0200 Subject: [PATCH] Added support of MergeValue. --- src/Tabs.php | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Tabs.php b/src/Tabs.php index 487ff0b..9f53d57 100644 --- a/src/Tabs.php +++ b/src/Tabs.php @@ -4,6 +4,7 @@ use RuntimeException; use Laravel\Nova\Panel; +use Illuminate\Http\Resources\MergeValue; use Laravel\Nova\Contracts\ListableField; class Tabs extends Panel @@ -45,22 +46,41 @@ public function addTab($panel): self ]); $this->data[] = $panel; } elseif ($panel instanceof Panel) { - foreach ($panel->data as $field) { - if ($field instanceof ListableField || $field instanceof Panel) { - $this->addTab($field); - continue; - } + $this->addFields($panel->name, $panel->data); + } else { + throw new RuntimeException('Only listable fields or Panel allowed.'); + } - $field->panel = $this->name; + return $this; + } - $field->withMeta([ - 'tab' => $panel->name, - ]); + /** + * Add fields to the Tab. + * + * @param string $tab + * @param array $fields + * @return \DKulyk\Nova\Tabs + */ + public function addFields($tab, array $fields) + { + foreach ($fields as $field) { + if ($field instanceof ListableField || $field instanceof Panel) { + $this->addTab($field); + continue; + } - $this->data[] = $field; + if ($field instanceof MergeValue) { + $this->addFields($tab, $field->data); + continue; } - } else { - throw new RuntimeException('Only listable fields or Panel allowed.'); + + $field->panel = $this->name; + + $field->withMeta([ + 'tab' => $tab, + ]); + + $this->data[] = $field; } return $this;