Skip to content

Commit

Permalink
Merge pull request #247 from crynobone/patch-2
Browse files Browse the repository at this point in the history
Fixes `HasTabs` trait hides relationship panels on Laravel Nova 4.12+
  • Loading branch information
marcfil authored Sep 8, 2022
2 parents 7db3533 + 6c9fc60 commit a0f249c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"require": {
"php": "^7.4|^8",
"laravel/nova": "^4.0",
"laravel/nova": "^4.12",
"ext-json": "*"
},
"require-dev": {
Expand Down
20 changes: 11 additions & 9 deletions src/Traits/HasTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ trait HasTabs
*/
protected function resolvePanelsFromFields(NovaRequest $request, FieldCollection $fields, $label)
{
[$relationPanels, $fields] = $fields->transform(function ($field) {
return $field instanceof BehavesAsPanel && !$field->assignedPanel instanceof Tabs ? $field->asPanel() : $field;
[$defaultFields, $fieldsWithPanels] = $fields->each(function ($field) {
if ($field instanceof BehavesAsPanel && !$field->assignedPanel instanceof Tabs) {
$field->asPanel();
}
})->partition(function ($field) {
return $field instanceof Panel;
});

[$defaultFields, $fieldsWithPanels] = $fields->partition(function ($field) {
return ! isset($field->panel) || blank($field->panel);
});

Expand All @@ -44,14 +42,18 @@ protected function resolvePanelsFromFields(NovaRequest $request, FieldCollection
})->toBase();

if ($panels->where('component', 'tabs')->isEmpty()) {
return parent::resolvePanelsFromFields($request, $fields, $label);
return $this->panelsWithDefaultLabel(
$panels,
$defaultFields->values(),
$label
);
}

[$relationshipUnderTabs, $panels] = $panels->partition(function ($panel) {
return $panel->component === 'relationship-panel' && $panel->meta['fields'][0]->assignedPanel instanceof Tabs;
});

$panels->transform(function($panel, $key) use($relationshipUnderTabs) {
$panels->transform(function($panel, $key) use ($relationshipUnderTabs) {

if ($panel->component === 'tabs') {

Expand All @@ -74,7 +76,7 @@ protected function resolvePanelsFromFields(NovaRequest $request, FieldCollection
});

return $this->panelsWithDefaultLabel(
$panels->merge($relationPanels),
$panels,
$defaultFields->values(),
$label
);
Expand Down

0 comments on commit a0f249c

Please sign in to comment.