概述
简介

Entry 类可以在 Filament\Infolists\Components 命名空间中找到。它们位于组件的 Schema 数组中。Filament 包含许多内置的 Entry:
你也可以创建自定义 Entry,以你希望的形式显示数据。
条目(Entry)可以使用静态 make() 方法创建,传入其唯一名称。通常,Entry 的名称对应于 Eloquent 模型的属性名。你可以使用“点语法”访问关联中的属性:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
TextEntry::make('author.name')

Entry 内容 (state)
Entry 旨在提供一种简单易用、优化展示 Eloquent 记录数据的方式。尽管如此,它很灵活,你可以展示任何来源的数据,不只是 Eloquent 记录的属性。
Entry 展示的数据称为“状态”。当使用面板资源时,信息列表了解它们要展示的记录。也就是说,Entry 的状态是基于记录的属性值设置的。比如,如果 Entry 用在 PostResource 的信息列表中,那么当前贴文(post)的 title 属性值将会被显示。
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
如果你想访问存储在关联中的值,你可以使用“点语法”。首先是你要访问数据的关联名,随后紧跟着点号,然后是属性名:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('author.name')
你也可以使用“点语法” 访问 Eloquent 模型中的 JSON/数组字段的值。首先是属性名,紧随着点号,最后是你想要读取的 JSON 对象的键名:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('meta.title')
设置 Entry 状态
使用 state() 方法,你可以将你自己的状态传入到 Entry 中:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->state('Hello, world!')
state() 方法也可以接受函数来动态计算其状态。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
设置 Entry 的默认状态
当 Entry 为空(其状态值为 null)时,你可以使用 default() 方法定义要使用的备用状态值。该方法将会视默认状态为真实状态,使得像图片或者颜色这些 Entry 可以展示默认图片或者颜色。
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->default('Untitled')
Entry 为空时添加占位符文本
有时,你想在 Entry 为空状态值式显示占位符文本,其使用青灰色文本。这与默认值不同,因为占位符永远是文本,且不会被当作真实状态。
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->placeholder('Untitled')

设置 Entry 的标签
默认情况下,Entry 的标签(展示在信息列表头部),是由 Entry 的名称生成。你可以使用 label() 方法对其自定义:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->label('Full name')
除了允许静态值之外,label() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
如果你想本地化翻译字符,以此方式自定义标签很有用:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->label(__('entries.name'))
隐藏 Entry 标签
TIP
如果你想要隐藏条目(Entry)的标签,可能是因 为你尝试将条目用于任意文本或 UI。条目专门设计用于以结构化方式显示数据,而 Prime 组件 是用于渲染基本独立静态内容(例如文本、图像和按钮(操作))的简单组件。你可以考虑使用 Prime 组件。
将标签设置为空字符串来隐藏它可能很诱人,但不建议这样做。即使标签的用途在视觉上很清晰,将其设置为空字符串也无法向屏幕阅读器传达条目的用途。你应该使用 hiddenLabel() 方法,这样虽然在视觉上隐藏了标签,但屏幕阅读器仍然可以访问它:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->hiddenLabel()
或者,你也可以传入布尔值以控制是否隐藏标签:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->hiddenLabel(FeatureFlag::active())
除了允许静态值之外,hiddenLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
点击 Entry 时打开 URL
使用 url() 方法,并传入一个 URL,你可以点击 Entry 来打开 URL。
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->url('/about/titles')
你也可以传入一个函数到 url() 方法中,来动态计算 URL。比如,通过将 $record 作为参数注入,你可以访问对应信息列表的当前 Eloquent 记录:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->url(fn (Post $record): string => route('posts.edit', ['post' => $record]))
如果你使用了面板资源,你可以使用 getUrl() 方法为该记录生成到页面的链接:
use App\Filament\Posts\PostResource;
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->url(fn (Post $record): string => PostResource::getUrl('edit', ['record' => $record]))
传递给 url() 的函数可以注入各种 utility 作为参数。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
你也可以选择在新标签页中打开 URL:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->url(fn (Post $record): string => PostResource::getUrl('edit', ['record' => $record]))
->openUrlInNewTab()
或者,你也可以传入一个布尔值,用以控制 URL 是否应该在新标签页中打开:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->url(fn (Post $record): string => PostResource::getUrl('edit', ['record' => $record]))
->openUrlInNewTab(FeatureFlag::active())
除了允许静态值之外,openUrlInNewTab() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
隐藏 Entry
你可以隐藏 Entry:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('role')
->hidden()
或者,你也可以传入一个布尔值,以控制是否隐藏 Entry:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('role')
->hidden(! FeatureFlag::active())
除了允许静态值之外,hidden() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
此外,你也可以使用 visible() 方法来控制是否隐藏条目。在某些情况下,此方法可以让你的代码更具可读性:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('role')
->visible(FeatureFlag::active())
除了允许静态值之外,visible() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
NOTE
如果同时使用了 hidden() 和 visible() 方法,那么它们都需要告知该条目是否应该展示。
使用 JavaScript 隐藏 Entry
如果你需要根据用户交互隐藏条目,可以使用 hidden() 或者 visible() 方法,并传入一个使用 utility 注入的函数,以确定该 Entry 是否该隐藏:
use Filament\Forms\Components\Select;
use Filament\Infolists\Components\IconEntry;
Select::make('role')
->options([
'user' => 'User',
'staff' => 'Staff',
])
->live()
IconEntry::make('is_admin')
->boolean()
->hidden(fn (Get $get): bool => $get('role') !== 'staff')
本例中,role 字段设置成 live(),这意味着,该 role 字段每次发生变化时, Schema 都会重新加载。这将会导致传入 hidden() 方法的函数重新计算,使之在 role Entry 未设为 staff 时隐藏 is_admin 字段。
不过,每次都重新加载 Schema 会导致每次都需要重新发起网络请求,因为你没办法在客户端重新运行 PHP 函数。这对于性能不太友好。
作为替代方案,你可以编写 JavaScript 使之基于另一个字段值隐藏条目。这可以通过将 JavaScript 表达式传递给 hiddenJs() 方法来实现:
use Filament\Forms\Components\Select;
use Filament\Infolists\Components\IconEntry;
Select::make('role')
->options([
'user' => 'User',
'staff' => 'Staff',
])
IconEntry::make('is_admin')
->boolean()
->hiddenJs(<<<'JS'
$get('role') !== 'staff'
JS)
虽然,传递给 hiddenJs() 的代码非常类似于 PHP,但它其实是 JavaScript。Filament 为 JavaScript 提供了 $get() 实用函数,使之行为与 PHP 的等效函数非常相似,而无需依赖于 Entry 的 live()。
visibleJs() 方法的用法也类似于 hiddenJs(),它用以控制 Entry 是否为可见:
use Filament\Forms\Components\Select;
use Filament\Infolists\Components\IconEntry;
Select::make('role')
->options([
'user' => 'User',
'staff' => 'Staff',
])
IconEntry::make('is_admin')
->boolean()
->visibleJs(<<<'JS'
$get('role') === 'staff'
JS)
NOTE
如果同时使用了 hiddenJs() 和 visibleJs(),则需要它们都说明该 Entry 是否可见才能显示。
基于当前操作隐藏 Entry
Schema 的“操作(Operaton)”指的是在其上面执行的当前 Action。通常,如果你使用的是面板资源,则可以是 create、edit 或者 view。
你可以通过将操作传递给 hiddenOn() 方法来基于当前操作隐藏 Entry:
use Filament\Infolists\Components\IconEntry;
IconEntry::make('is_admin')
->boolean()
->hiddenOn('edit')
// is the same as
IconEntry::make('is_admin')
->boolean()
->hidden(fn (string $operation): bool => $operation === 'edit')
你可以将一个操作数组传递个 hiddenOn() 方法,如果当前操作是数组中的其中一项,该 Entry 将会被隐藏:
use Filament\Infolists\Components\IconEntry;
IconEntry::make('is_admin')
->boolean()
->hiddenOn(['edit', 'view'])
// is the same as
IconEntry::make('is_admin')
->boolean()
->hidden(fn (string $operation): bool => in_array($operation, ['edit', 'view']))
NOTE
hiddenOn() 方法将会覆盖任何之前的 hidden() 调用,反之亦然。
此外,你也可以使用 visibleOn() 控制是否隐藏 Entry。在某些情况下,该方法会让你的代码更具可读性:
use Filament\Infolists\Components\IconEntry;
IconEntry::make('is_admin')
->boolean()
->visibleOn('create')
IconEntry::make('is_admin')
->boolean()
->visibleOn(['create', 'edit'])
NOTE
VisibleOn() 方法将会覆盖任何之前的 visible() 调用,反之亦然。
行内标签
Entry 可以设置为让标签与之同行显示,而不是让标签在其上方。这对于有许多标签的信息列表非常有用,因为其纵向空间非常宝贵。要让 Entry 的标签在行内展示,请使用 inlineLabel() 方法:
use Filament\Infolists\Components\TextEntry;
TextInput::make('name')
->inlineLabel()

此外,你也可以传入一个布尔值,控制其标签是否行内显示:
use Filament\Infolists\Components\TextInput;
TextInput::make('name')
->inlineLabel(FeatureFlag::active())
除了允许静态值之外,inlineLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
一次性在多处使用行内标签
如果你希望在 布局组件(例如 section 或 tab)中以内联方式显示所有标签,则可以在组件本身上使用 inlineLabel(),其中所有条目的标签都将以内联方式显示:
use Filament\Infolists\Components\TextInput;
use Filament\Schemas\Components\Section;
Section::make('Details')
->inlineLabel()
->entries([
TextInput::make('name'),
TextInput::make('email')
->label('Email address'),
TextInput::make('phone')
->label('Phone number'),
])

你也可以在全体 Schema 上使用 inlineLabel() 来行内显示所有标签:
use Filament\Schemas\Schema;
public function infolist(Schema $schema): Schema
{
return $schema
->inlineLabel()
->components([
// ...
]);
}
在布局组件或 Schema 上使用 inlineLabel() 时,你仍然可以通过在条目上使用 inlineLabel(false) 方法选择退出单个条目的内联标签:
use Filament\Infolists\Components\TextInput;
use Filament\Schemas\Components\Section;
Section::make('Details')
->inlineLabel()
->entries([
TextInput::make('name'),
TextInput::make('email')
->label('Email address'),
TextInput::make('phone')
->label('Phone number')
->inlineLabel(false),
])
为条目添加 Tooltip
你可以指定鼠标悬停在条目上时显示的 Tooltip:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->tooltip('Shown at the top of the page')
除了允许静态值之外,tooltip() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

对齐 Entry 内容
你可以使用 alignStart()、alignCenter() 或 alignEnd() 方法将条目的内容与开始(在从左到右的界面中为左侧,在从右到左的界面中为右侧)、中心或结束(在从左到右的界面中为右侧,在从右到左的界面中为左侧)对齐:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->alignStart() // This is the default alignment.
TextEntry::make('title')
->alignCenter()
TextEntry::make('title')
->alignEnd()
或者,你可以将 Alignment 枚举传递给 alignment() 方法:
use Filament\Infolists\Components\TextEntry;
use Filament\Support\Enums\Alignment;
TextEntry::make('title')
->alignment(Alignment::Center)
除了允许静态值之外,alignment() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
添加额外内容到 Entry 中
条目包含许多“插槽”,可在子 Schema 中插入内容。插槽可以接受文本、任何 Schema 组件、操作 和 操作组。通常,Prime 组件 用于提供内容。
以下插槽适用于所有条目:
aboveLabel()beforeLabel()afterLabel()belowLabel()aboveContent()beforeContent()afterContent()belowContent()
除了允许静态值之外,这些插槽方法也允许接受函数来动态计算它们的值。你可以注入各种 utility 到函数中作为参数。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
要插入普通文本,你可以传入字符串到这些方法中:
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->belowContent('This is the user\'s full name.')

To insert a schema component, often a prime component, you can pass the component to the method:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Text;
use Filament\Support\Enums\FontWeight;
TextEntry::make('name')
->belowContent(Text::make('This is the user\'s full name.')->weight(FontWeight::Bold))

To insert an action or action group, you can pass the action or action group to the method:
use Filament\Actions\Action;
use Filament\Infolists\Components\TextEntry;
TextEntry::make('name')
->belowContent(Action::make('generate'))

你可以通过将内容数组传递给方法,将任意内容组合插入插槽:
use Filament\Actions\Action;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->belowContent([
Icon::make(Heroicon::InformationCircle),
'This is the user\'s full name.',
Action::make('generate'),
])

你可以通过将内容数组传递给 Schema::start()(默认)、Schema::end() 或 Schema::between() 来对齐插槽中的内容:
use Filament\Actions\Action;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Flex;
use Filament\Schemas\Components\Icon;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->belowContent(Schema::end([
Icon::make(Heroicon::InformationCircle),
'This is the user\'s full name.',
Action::make('generate'),
]))
TextEntry::make('name')
->belowContent(Schema::between([
Icon::make(Heroicon::InformationCircle),
'This is the user\'s full name.',
Action::make('generate'),
]))
TextEntry::make('name')
->belowContent(Schema::between([
Flex::make([
Icon::make(Heroicon::InformationCircle)
->grow(false),
'This is the user\'s full name.',
]),
Action::make('generate'),
]))
TIP
正如你在上面的 Schema::between() 示例中所见,我们使用了一个 Flex 组件 将图标和文本组合在一起,使它们之间没有空白。图标使用 grow(false) 来防止其占用一 半的水平空间,从而允许文本占用剩余的空间。

Adding extra content above an entry's label
You can insert extra content above an entry's label using the aboveLabel() method. You can pass any content to this method, like text, a schema component, an action, or an action group:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->aboveLabel([
Icon::make(Heroicon::Star),
'This is the content above the entry\'s label'
])
除了允许静态值之外,aboveLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

Adding extra content before an entry's label
You can insert extra content before an entry's label using the beforeLabel() method. You can pass any content to this method, like text, a schema component, an action, or an action group:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->beforeLabel(Icon::make(Heroicon::Star))
除了允许静态值之外,beforeLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

Adding extra content after an entry's label
You can insert extra content after an entry's label using the afterLabel() method. You can pass any content to this method, like text, a schema component, an action, or an action group:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->afterLabel([
Icon::make(Heroicon::Star),
'This is the content after the entry\'s label'
])
除了允许静态值之外,afterLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

By default, the content in the afterLabel() schema is aligned to the end of the container. If you wish to align it to the start of the container, you should pass a Schema::start() object containing the content:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->afterLabel(Schema::start([
Icon::make(Heroicon::Star),
'This is the content after the entry\'s label'
]))
除了允许静态值之外,afterLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

Adding extra content below an entry's label
You can insert extra content below an entry's label using the belowLabel() method. You can pass any content to this method, like text, a schema component, an action, or an action group:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->belowLabel([
Icon::make(Heroicon::Star),
'This is the content below the entry\'s label'
])
除了允许静态值之外,belowLabel() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

NOTE
This may seem like the same as the aboveContent() method. However, when using inline labels, the aboveContent() method will place the content above the entry, not below the label, since the label is displayed in a separate column to the entry content.
Adding extra content above an entry's content
You can insert extra content above an entry's content using the aboveContent() method. You can pass any content to this method, like text, a schema component, an action, or an action group:
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Icon;
use Filament\Support\Icons\Heroicon;
TextEntry::make('name')
->aboveContent([
Icon::make(Heroicon::Star),
'This is the content above the entry\'s content'
])
除了允许静态值之外,aboveContent() 方法也可以接受函数来动态计算其值。你可以将各种 utility 作为参数注入到函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Entry | Filament\Infolists\Components\Entry | $component | The current entry 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 <code>create</code>, <code>edit</code>, or <code>view</code>. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |

NOTE
This may seem like the same as the belowLabel() method. However, when using inline labels, the belowLabel() method will place the content below the label, not above the entry's content, since the label is displayed in a separate column to the entry content.
















