Skip to content

dcasia/resource-navigation-tab

Repository files navigation

Resource Navigation Tab

Latest Version on Packagist Total Downloads License

Organize your resource fields into tabs.

Resource Navigation Tab in Action

Installation

You can install the package via composer:

composer require digital-creative/resource-navigation-tab

Basic Usage

First, import HasResourceNavigationTabTrait trait into your resource and start grouping your fields with the ResourceNavigationField object:

use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationField;

class ExampleNovaResource extends Resource {
 
    use HasResourceNavigationTabTrait;

    public function fields(NovaRequest $request): array
    {
        return [
            ResourceNavigationField::make('Information')
                ->fields([
                    Text::make('Name'),
                    Text::make('Age'),
                    HasMany::make('Hobbies'),
                ]),
            ResourceNavigationField::make('Activities')->fields([ ... ]),
            ResourceNavigationField::make('Social Interactions')->fields([ ... ]),
            ResourceNavigationField::make('Settings')->fields([ ... ]),
        ];
    }

}

Once setup navigate to your resource detail view, and you should be presented with this card:

Resource Navigation Tab in Action

Every defined card will be shown on every tab by default, however you can choose which card you want to show when a specific tab is selected:

use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationField;
use DigitalCreative\ResourceNavigationTab\CardMode;

class ExampleNovaResource extends Resource {

    use HasResourceNavigationTabTrait;
 
    public function fields(NovaRequest $request): array
    {
        return [
            ResourceNavigationField::make('Information'), // show all the available cards by default
            ResourceNavigationField::make('Activities')->withCards([ DailySalesCard::class, ClientProfileCard::class ]), // only show these cards when this tab is active
            ResourceNavigationField::make('Settings')->withoutCards(), // hide all cards when this tab is active
        ];
    }

    public function cards(NovaRequest $request): array
    {
        return [
            new ClientPerformanceCard(),
            new DailySalesCard(),
            new ClientProfileCard()
        ];
    }

}

⭐️ Show Your Support

Please give a ⭐️ if this project helped you!

Other Packages You Might Like

License

The MIT License (MIT). Please see License File for more information.