In some cases, forms can become long and complicated due to the amount of data or fields. To improve usability, you might want to separate certain data fields or content into different tabs.
Using the Latest Botble Version
To use this feature, ensure your script is updated to the latest version of Botble. In your form, you can achieve this by using the ->addTab()
method:
use Botble\Blog\Models\Post;
public function setup(): void
{
$this
->model(Post::class)
->addTab('Tab item label', view('plugins/your-plugin::partials.some-view'));
// ...
}
Adding Tabs to Existing Forms
If you want to add a tab to an existing form in the core or any plugin, you can use the following hook:
use Botble\Blog\Forms\PostForm;
PostForm::extend(function (PostForm $form) {
$form->addTab(
'Tab item label',
view('plugins/your-plugin::partials.some-view')
);
}, priority: 999);
Using Botble Version 7.3.8 or Older
For versions from 7.3.8 and earlier, you can add tabs to forms using the following hooks:
Hook into BASE_FILTER_REGISTER_CONTENT_TABS
to Add a New Tab:
use Illuminate\Support\Facades\Blade;
add_filter(BASE_FILTER_REGISTER_CONTENT_TABS, function (?string $html, Model $model): ?string {
return $html . Blade::render('<x-core::tab.item id="my-tab" label="My Tab" />');
}, 999, 2);
Hook into BASE_FILTER_REGISTER_CONTENT_TAB_INSIDE
to Insert Content into the New Tab:
use Illuminate\Support\Facades\Blade;
add_filter(BASE_FILTER_REGISTER_CONTENT_TAB_INSIDE, function (?string $html, Model $model): ?string {
return $html . Blade::render('<x-core::tab.pane id="my-tab">Tab content</x-core::tab.pane>');
}, 999, 2);