• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

eminiarts/nova-tabs: Laravel Nova Tabs Package

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

eminiarts/nova-tabs

开源软件地址(OpenSource Url):

https://github.com/eminiarts/nova-tabs

开源编程语言(OpenSource Language):

PHP 51.1%

开源软件介绍(OpenSource Introduction):

Nova Tabs, awesome resource tabs for Nova


Latest Version on Github

  1. Requirements
  2. Installation
  3. Usage
    1. Tabs Panel
    2. Relationship Tabs
    3. Combine Fields and Relations in Tabs
    4. Actions in Tabs
    5. Tabs on Edit View
  4. Tab object
  5. Customization
    1. Tab
    2. Default search
    3. Display more than 5 items
  6. Upgrade to V2

Requirements

  • php: ^7.4 | ^8
  • laravel/nova: ^4

For Laravel Nova Version 3, please use nova-tabs v1 instead.

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require eminiarts/nova-tabs

Usage

Tabs Panel

image

You can group fields of a resource into tabs, you can use an array or a Tab object (as of 1.4.0)::

// in app/Nova/Resource.php

use Eminiarts\Tabs\Traits\HasTabs;
use Eminiarts\Tabs\Tabs;

class User extends Resource
{
    use HasTabs;
    
    public function fields(Request $request)
    {
       return [
   
           new Tabs('Some Title', [
               'Balance'    => [
                   Number::make('Balance', 'balance'),
                   Number::make('Total', 'total'),
               ],
               'Other Info' => [
                   Number::make('Paid To Date', 'paid_to_date'),
               ],
           ]),
       ];
   }
}

or

// in app/Nova/Resource.php

use Eminiarts\Tabs\Traits\HasTabs;
use Eminiarts\Tabs\Tabs;
use Eminiarts\Tabs\Tab;

class User extends Resource
{
    use HasTabs;
    
    public function fields(Request $request)
    {
       return [
         Tabs::make('Some Title', [
            Tab::make('Balance', [
                Number::make('Balance', 'balance'),
                Number::make('Total', 'total'),
            ]),
            Tab::make('Other Info', [
                Number::make('Paid To Date', 'paid_to_date')
            ]),
         ]),
      ];
    }
 }

The first tab in every Tabs instance will be auto-selected.

Relationship Tabs

image These are a bit outdated, as the search and create buttons now show within the panel down where the actual content is displayed, not in the tab panel.

// in app/Nova/Resource.php

use Eminiarts\Tabs\Tabs;
use Laravel\Nova\Fields\HasMany;
use Eminiarts\Tabs\Traits\HasTabs;

class User extends Resource
{
    use HasTabs;
    
    public function fields(Request $request)
    {
        return [
           Tabs::make('Relations', [
                HasMany::make('Invoices'),
                HasMany::make('Notes'),
                HasMany::make('Contacts')
            ]),

        ];
    }
}

Combine Fields and Relations in Tabs

image

image

use Eminiarts\Tabs\Tabs;
use Laravel\Nova\Fields\HasMany;
use Eminiarts\Tabs\Traits\HasTabs;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;

class User extends Resource
{
    use HasTabs;
    
    public function fields(Request $request)
    {
          return [
              Tabs::make(__('Client Custom Details'), [
                  new Panel(__('Details'), [
                          ID::make('Id', 'id')->rules('required')->hideFromIndex(),
                          Text::make('Name', 'name'),
                  ]),
                  HasMany::make('Invoices')
              ]),
         ];
    }
}

Actions in Tabs

If your Model uses the Laravel\Nova\Actions\Actionable Trait you can put the Actions into a Tab like this:

// in app/Nova/Resource.php

use Eminiarts\Tabs\Tabs;
use Eminiarts\Tabs\Tab;
use Eminiarts\Tabs\Traits\HasTabs;
use Eminiarts\Tabs\Traits\HasActionsInTabs; // Add this Trait
use Laravel\Nova\Actions\ActionResource; // Import the Resource

class Client extends Resource
{
    use HasTabs;
    use ActionsInTabs; // Use this Trait

    public function fields(Request $request)
    {
        return [
            Tabs::make('Client Custom Details', [
                Tab::make('Address', [
                    ID::make('Id', 'id'),
                    Text::make('Name', 'name')->hideFromDetail(),
                ]),
                Tab::make('Invoices', [
                    HasMany::make('Invoices'),
                ]),
                Tab::make('Actions', [
                    $this->actionfield(), // Add Actions whererver you like.
                ]),
            ]),
        ];
    }
}

Tabs on Edit View

image

Tabs are always shown on edit view as of Nova 4 for now.

Tab object

As of v1.4.0 it's possible to use a Tab class instead of an array to represent your tabs.

Property Type Default Description
name string null The name of the tab, used for the slug. Defaults to the title if not set
showIf bool or Closure null If the result is truthy the tab will be shown. showIf takes priority over showUnless and if neither are set, true is assumed.
showUnless bool or Closure null If the result is falsy the tab will be shown. showIf takes priority over showUnless and if neither are set, true is assumed.
bodyClass string or array Empty array A string or string array of classes to add to the tab's body. This sets the bodyClass property, if you want to append you can use addBodyClass instead.

Customization

Display more than 5 items

By default, any HasMany, BelongsToMany and MorphMany fields show 5 items in their index. You can use Nova's built-in static property $perPageViaRelationship on the respective resource to show more (or less).

Upgrade to 2.0.0

  • Breaking changes
    • Removed selectFirstTab, first tab is always displayed first.
    • Even if you have other panels, tabs will always show up first and has the toolbar.
    • TabsOnEdit is gone and non relational tabs will simply always display on edit.
    • I don't use dusk, so didn't check the tests for it either, they might be broken.
    • Added Eminiarts\Tabs\Traits\HasTabs to overwrite Nova 4 default panel methods in Laravel\Nova\ResolveFields.
    • Moved Eminiarts\Tabs\ActionsInTabs to Eminiaarts\Tabs\Traits\HasActionsInTabs.
    • Added position method to Tab to fix relational tabs showing up last.

Credits

Banner was created with https://banners.beyondco.de/




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap