Schema
Tabs
简介
有些 Schema 冗长且复杂。你可以使用 Tabs(选项卡/标签页)来减少组件的一次性可见数量:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
除了允许静态值之外,make()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |

设置默认激活标签
默认情况下,打开的是第一个 Tab。你可以使用 activeTab()
方法修改默认打开的 Tab:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
->activeTab(2)
除了允许静态值之外,activeTab()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
设置 Tab 图标
使用 icon()
方法,可以为 Tab 设置图标:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Support\Icons\Heroicon;
Tabs::make('Tabs')
->tabs([
Tab::make('Notifications')
->icon(Heroicon::Bell)
->schema([
// ...
]),
// ...
])
除了允许静态值之外,icon()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |

设置 Tab 图标位置
使用 iconPosition()
方法可以将图标放在标签的前后:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Support\Enums\IconPosition;
use Filament\Support\Icons\Heroicon;
Tabs::make('Tabs')
->tabs([
Tab::make('Notifications')
->icon(Heroicon::Bell)
->iconPosition(IconPosition::After)
->schema([
// ...
]),
// ...
])
除了允许静态值之外,iconPosition()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |

设置 Tab 徽章
使用 badge()
方法,可以为选项卡设置徽章:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Notifications')
->badge(5)
->schema([
// ...
]),
// ...
])
除了允许静态值之外,badge()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |

使用 badgeColor()
方法,你可以修改徽章颜色:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Notifications')
->badge(5)
->badgeColor('info')
->schema([
// ...
]),
// ...
])
除了允许静态值之外,badgeColor()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |

在选项卡中使用网格列
你可以使用 columns()
方法自定义 Tab 中的网格:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
])
->columns(3),
// ...
])
除了允许静态值之外,columns()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
使用垂直选项卡
使用 vertical()
你可以将选项卡渲染成垂直模式:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
->vertical()

或者,你 可以传入布尔值到 vertical()
方法,用以控制选项卡是否垂直展示:
use Filament\Schemas\Components\Tabs;
Tabs::make('Tabs')
->tabs([
// ...
])
->vertical(FeatureFlag::active())
除了允许静态值之外,vertical()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
移除样式容器
默认情况下,Tabs 及其内容被包裹在一个样式为卡片的容器中,你可以使用 contained()
移除样式容器:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
->contained(false)
除了允许静态值之外,contained()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
在用户 Session 中持久化当前 Tab
默认情况下,当前 Tab 不会在浏览器的本地存储中持久化。你可以使用 persistTab()
方法修改该行为。你也必须为 Tabs 组件传入唯一 id()
,以在 App 中和其它组的 Tabs 区分开来。该 ID 会被用作本地存储的键,保存当前标签页:
use Filament\Schemas\Components\Tabs;
Tabs::make('Tabs')
->tabs([
// ...
])
->persistTab()
->id('order-tabs')
或者,persistTab()
方法接受一个布尔值,用以控制 Tab 是否应该持久化:
use Filament\Schemas\Components\Tabs;
Tabs::make('Tabs')
->tabs([
// ...
])
->persistTab(FeatureFlag::active())
->id('order-tabs')
除了允许静态值之外,persistTab()
和 id()
方法也接受函数来动态计算它们的值。你可以将多个 utility 作为参数注入到函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
在 URL 查询字符串中持久化当前 Tab
默认情况下,当前 Tab 不会在 URL 查询字符串中持久化,你可以使用 persistTabInQueryString()
方法修改此行为:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
->persistTabInQueryString()
启用后,当前 Tab 在 URL 查询字符串中使用 tab
键持久化。你可以将其传入 persistTabInQueryString()
方法中修改此键:
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
Tabs::make('Tabs')
->tabs([
Tab::make('Tab 1')
->schema([
// ...
]),
Tab::make('Tab 2')
->schema([
// ...
]),
Tab::make('Tab 3')
->schema([
// ...
]),
])
->persistTabInQueryString('settings-tab')
除了允许静态值之外,persistTabInQueryString()
方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Component | Filament\Schemas\Components\Component | $component | The current component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current schema data. Validation is not run on form fields. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
Still need help? Join our Discord community or open a GitHub discussion