Field's Grouping by the tab.
composer require armincms/nova-tabFirst create your tab like follow.
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();
Then, to insert each field into the created tab; pass the name and the group name
into the withTab macro method.for example:
Text::make('Name')->withTab('tab-name', 'first-group-name');
Text::make('Gender')->withTab('tab-name', 'second-group-name');
First create your tab like follow. Then; for define tab field's, you can use the group method.
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();
By default we'll active the first tab. if you want customize the active tab,
it's availabe by call the active method on the tab group.
It's possible to customize the tab label's by passing the label string through the
label method on the group.
If you want jsutify the tab for fill screen; you can call fullWidth method on the Tab::class
- base example:
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();
}
- Fullwidth tab example:
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('*'),
]);
}
You can add multiple tab into form and detail page.
for this situation; just needs making different name for different tabs.
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('*'),
]);
}
You can add tab into Panel but you never can add Panel into tab.
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');
}),
])
];
}
If some fields missing in the tab, with macro method withTab you can add the
missed field into the tab. like following example:
Text::make('FieldName')->withTab('tab-name', 'group-name')