概述
简介

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'))


