跳到主要内容
版本:4.x

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',
]
Key-value entry

如果你在 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.
UtilityTypeParameterDescription
EntryFilament\Infolists\Components\Entry$componentThe current entry component instance.
Get functionFilament\Schemas\Components\Utilities\Get$getA function for retrieving values from the current schema data. Validation is not run on form fields.
LivewireLivewire\Component$livewireThe Livewire component instance.
Eloquent model FQN?string<Illuminate\Database\Eloquent\Model>$modelThe Eloquent model FQN for the current schema.
Operationstring$operationThe current operation being performed by the schema. Usually <code>create</code>, <code>edit</code>, or <code>view</code>.
Eloquent record?Illuminate\Database\Eloquent\Model$recordThe Eloquent record for the current schema.
Statemixed$stateThe 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.
UtilityTypeParameterDescription
EntryFilament\Infolists\Components\Entry$componentThe current entry component instance.
Get functionFilament\Schemas\Components\Utilities\Get$getA function for retrieving values from the current schema data. Validation is not run on form fields.
LivewireLivewire\Component$livewireThe Livewire component instance.
Eloquent model FQN?string<Illuminate\Database\Eloquent\Model>$modelThe Eloquent model FQN for the current schema.
Operationstring$operationThe current operation being performed by the schema. Usually <code>create</code>, <code>edit</code>, or <code>view</code>.
Eloquent record?Illuminate\Database\Eloquent\Model$recordThe Eloquent record for the current schema.
Statemixed$stateThe current value of the entry.