信息列表
Repeatable entry
简介
RepeatableEntry 允许你让数组或关联中的以一组 Entry 及布局组件进行重复:
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\TextEntry;
RepeatableEntry::make('comments')
->schema([
TextEntry::make('author.name'),
TextEntry::make('title'),
TextEntry::make('content')
->columnSpan(2),
])
->columns(2)
如你所见,RepeatableEntry 有一个可嵌入的 schema(),可以重复每一项。
比如,该条目的值可能如下:
[
[
'author' => ['name' => 'Jane Doe'],
'title' => 'Wow!',
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget aliquam ultricies, nunc nisl aliquet nunc, quis aliquam nisl.',
],
[
'author' => ['name' => 'John Doe'],
'title' => 'This isn\'t working. Help!',
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisl eget aliquam ultricies, nunc nisl aliquet nunc, quis aliquam nisl.',
],
]
此外,comments 和 author 可能是 Eloquent 关联,title 和 content 可以是 Comment 模型的属性,而 name 可以是 Author 模型的一个属性。Filament 将会自动处理关联的加载,并以同样的方式展示数据。
Grid 布局
使用 grid() 方法,你可以将可重复项组织到列中:
use Filament\Infolists\Components\RepeatableEntry;
RepeatableEntry::make('comments')
->schema([
// ...
])
->grid(2)
该方法接收与 Grid 的 columns() 方法相同的选项。让你可以在各种临界点中响应式地定制 Grid 的列数。
除了允许静态值外,grid() 方法也接受一个函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
了解更多 utility 注入详情。 | Utility | 类型 | 参数 | 描述 |
|---|---|---|---|
| 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 create, edit, or view. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
移除样式容器
默认情况下,RepeatableEntry 中的每一项都被包装在一个样式为卡片的容器中,你可以使用 contained() 移除样式容器:
use Filament\Infolists\Components\RepeatableEntry;
RepeatableEntry::make('comments')
->schema([
// ...
])
->contained(false)
除了允许静态值外,contained() 方法也接受一个函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
了解更多 utility 注入详情。 | Utility | 类型 | 参数 | 描述 |
|---|---|---|---|
| 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 create, edit, or view. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
| State | mixed | $state | The current value of the entry. |
Table repeatable layout
You can present repeatable items in a table format using the table() method, which accepts an array of TableColumn objects. These objects represent the columns of the table, which correspond to any components in the schema of the entry:
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
use Filament\Infolists\Components\TextEntry;
RepeatableEntry::make('comments')
->table([
TableColumn::make('Author'),
TableColumn::make('Title'),
TableColumn::make('Published'),
])
->schema([
TextEntry::make('author.name'),
TextEntry::make('title'),
IconEntry::make('is_published')
->boolean(),
])
The labels displayed in the header of the table are passed to the TableColumn::make() method. If you want to provide an accessible label for a column but do not wish to display it, you can use the hiddenHeaderLabel() method:
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
TableColumn::make('Name')
->hiddenHeaderLabel()
You can enable wrapping of the column header using the wrapHeader() method:
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
TableColumn::make('Name')
->wrapHeader()
You can also adjust the alignment of the column header using the alignment() method, passing an Alignment option of Alignment::Start, Alignment::Center, or Alignment::End:
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
use Filament\Support\Enums\Alignment;
TableColumn::make('Name')
->alignment(Alignment::Center)
You can set a fixed column width using the width() method, passing a string value that represents the width of the column. This value is passed directly to the style attribute of the column header:
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
TableColumn::make('Name')
->width('200px')
Edit on GitHubStill need help? Join our Discord community or open a GitHub discussion