信息列表
Key-value entry
简介
键值条目(KeyValueEntry)允许你从一维 JSON 对象/PHP 数组中渲染键值对数据。
use Filament\Infolists\Components\KeyValueEntry;
KeyValueEntry::make('meta')
比如,该条目的状态值可能如下:
[
'description' => 'Filament is a collection of Laravel packages',
'og:type' => 'website',
'og:site_name' => 'Filament',
]

如果你在 Eloquent 中保存数据,你应该保证将 array
强制转换(cast)添加到模型属性中:
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $casts = [
'meta' => 'array',
];
// ...
}
自定义键(key)列的标签
使用 keyLabel()
方法自定义键列的标签:
use Filament\Infolists\Components\KeyValueEntry;
KeyValueEntry::make('meta')
->keyLabel('Property name')
>除了允许静态值外,keyLabel()
方法也接受一个函数来动态计算其值。你可以将多个 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 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. |
自定义值(key)列的标签
使用 valueLabel()
方法自定义值列的标签:
use Filament\Infolists\Components\KeyValueEntry;
KeyValueEntry::make('meta')
->valueLabel('Property value')
>除了允许静态值外,valueLabel()
方法也接受一个函数来动态计算其值。你可以将多个 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 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. |
Still need help? Join our Discord community or open a GitHub discussion