armincms / nova-tab
Laravel Nova 工具。
4.0.2
2020-03-16 09:51 UTC
Requires
- php: >=7.1.0
README
标签分组字段。
目录
安装
composer require armincms/nova-tab
快速开始
首先创建您的标签页,如下所示。
Tab::make('tab-name', [
'first-group-name' => 'First Group Label',
'second-group-name' => 'Second Group Label',
'fourth-group' => [
// group fields
],
'fifth-group' => function() {
return [
// group fields
];
}
])->fullwidth();
然后,要将每个字段插入到创建的标签页中;请将 name
和 group name
传递到 withTab
宏方法中。例如
Text::make('Name')->withTab('tab-name', 'first-group-name');
Text::make('Gender')->withTab('tab-name', 'second-group-name');
使用方法
首先创建您的标签页,如下所示。然后;为了定义 field's
标签,您可以使用 group
方法。
Tab::make('tab-name', function($tab) {
// pass fields by callback
$tab->group('first-tab-name', function($group) {
return [
// define your tab fields
];
});
// pass fields by array
// active your tab by `active` method
$tab->group('active-tab', [
// define your tab fields
])->active();
// custom label tab
$tab->group('custom-label-tab', function($group) {
// or inside the group
$group->label('My Custom Label');
return [
// define your tab fields
];
})->label('My Custom Label');
// full width tab by call `fullwidth` method
})->fullwidth();
活动标签页
默认情况下,我们将激活第一个标签页。如果您想自定义 active tab
,可以在标签 group
上调用 active
方法。
标签标签
您可以通过在 group
上的 label
方法中传递标签字符串来自定义 tab label's
。
全宽标签页
如果您想将标签页调整到全屏;您可以在 Tab::class
上调用 fullWidth
方法
注意1:您可以将任何 field
和 relation-field
添加到标签页中。
注意2:无法将 Panel
添加到标签页中。
注意3:可以将 tab
添加到 Panel
中。
- 基本示例
use Armincms\Tab\Tab;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return Tab::make('general', function($tab) {
$tab->group('general', [
ID::make()->sortable(),
Select::make('Tag')->options(function() {
return ['*' => 'all'];
})->default('*'),
])->label(__('General'));
$tab->group('SEO', [
Text::make('Title'),
])->active();
$tab->group('Relations', [
MorphToMany::make('Tag'),
])->label('Relations');
})->toArray();
}
- 全宽标签页示例
use Armincms\Tab\Tab;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return Tab::make('general', function($tab) {
$tab->group('general', [$this, 'generalFields'])->label(__('General'));
$tab->group('SEO', [
Text::make('Title'),
])->active();
$tab->group('Relations', [
MorphToMany::make('Tag'),
])->label('Relations');
})->fullwidth()->toArray();
}
public function generalFields()
{
return $this->merge([
ID::make()->sortable(),
Select::make('Tag')->options(function() {
return ['*' => 'all'];
})->default('*'),
]);
}
多标签页
您可以在 form
和 detail
页面上添加多个标签页。在这种情况下;只需为不同的标签页制作不同的名称。
注意1:您不能在多个标签页中添加相同的 relation-field
。它只与其中一个一起工作。
use Armincms\Tab\Tab;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
Tab::make('first-tab', function($tab) {
$tab->group('general', [$this, 'generalFields'])->label(__('General'));
$tab->group('SEO', [
Text::make('Title'),
])->active();
$tab->group('Relations', [
MorphToMany::make('Tag'),
])->label('Relations');
}),
Tab::make('second-tab', function($tab) {
$tab->group('general', [
ID::make()->sortable(),
Select::make('Tag')->options(function() {
return ['*' => 'all'];
})->default('*'),
])->label(__('General'));
$tab->group('SEO', [
Text::make('Title'),
])->active();
$tab->group('Relations', [
MorphToMany::make('Category'),
])->label('Relations');
}),
];
}
public function generalFields()
{
return $this->merge([
ID::make()->sortable(),
Select::make('Tag')->options(function() {
return ['*' => 'all'];
})->default('*'),
]);
}
与面板一起使用
您可以将标签添加到 Panel
中,但您永远不会将 Panel
添加到标签中。
use Armincms\Tab\Tab;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
new Panel('First Panel', [
Tab::make('general', function($tab) {
$tab->group('general', [
ID::make()->sortable(),
Select::make('Tag')->options(function() {
return ['*' => 'all'];
})->default('*'),
])->label(__('General'));
$tab->group('SEO', [
Text::make('Title'),
])->active();
$tab->group('Relations', [
MorphToMany::make('Tag'),
])->label('Relations');
}),
]),
}
关系
use Armincms\Tab\Tab;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
new Panel('My Panel', [
Tab::make('general', function($tab) {
$tab->group('Author', [
ID::make()->sortable(),
BelogsTo::make('User'),
])->label(__('General'));
$tab->group('Relations', [
MorphToMany::make('Tag'),
])->label('Relations');
}),
])
];
}
缺失的标签页
如果某些字段在标签页中缺失,使用宏方法 withTab
,您可以添加缺失的字段到标签页中。例如以下示例
Text::make('FieldName')->withTab('tab-name', 'group-name')