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

Icon entry

简介

图标条目(IconEntry)用于渲染表示该 Entry 状态的图标

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Icons\Heroicon;

IconEntry::make('status')
->icon(fn (string $state): string => match ($state) {
'draft' => Heroicon::OutlinedPencil,
'reviewing' => Heroicon::OutlinedClock,
'published' => Heroicon::OutlinedCheckCircle,
})
icon() 方法可以将多个 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.
Icon entry

自定义颜色

使用 color() 方法,你可以修改图标的颜色

use Filament\Infolists\Components\IconEntry;

IconEntry::make('status')
->color('success')

通过传入函数到 color(),你可以基于 Entry 状态自定义颜色:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('status')
->color(fn (string $state): string => match ($state) {
'draft' => 'info',
'reviewing' => 'warning',
'published' => 'success',
default => 'gray',
})
color() 方法可以将多个 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.
Icon entry with color

自定义大小

图标的默认尺寸是 IconSize::Large,你也可以将其自定义为 IconSize::ExtraSmallIconSize::SmallIconSize::MediumIconSize::ExtraLarge 或者 IconSize::TwoExtraLarge:

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Enums\IconSize;

IconEntry::make('status')
->size(IconSize::Medium)
除了允许静态值之外,size() 方法也接受一个函数来动态计算其值。你可以将多个 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.
Medium-sized icon entry

处理布尔值

使用 boolean() 方法,图标条目可以基于 Entry 状态的 true 或者 false 显示打勾或者 "X" 图标:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
->boolean()

如果模型类中的该属性已经强制转换成 bool 或者 boolean,Filament 可以检测到,你不用手动使用 boolean()

Icon entry to display a boolean

Optionally, you may pass a boolean value to control if the icon should be boolean or not:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
->boolean(FeatureFlag::active())
除了允许静态值之外,boolean() 方法也接受一个函数来动态计算其值。你可以将多个 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.

自定义布尔值图标

你可以自定义表示每个状态的图标

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Icons\Heroicon;

IconEntry::make('is_featured')
->boolean()
->trueIcon(Heroicon::OutlinedCheckBadge)
->falseIcon(Heroicon::OutlinedXMark)
除了允许静态值之外,trueIcon()falseIcon() 方法也接受通过函数来动态计算它们的值。你可以将多个 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.
Icon entry to display a boolean with custom icons

自定义布尔值颜色

你可以自定义表示每个状态的图标颜色

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
->boolean()
->trueColor('info')
->falseColor('warning')
除了允许静态值之外,trueColor()falseColor() 方法也接受函数以动态计算它们的值。你可以将多个 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.
Icon entry to display a boolean with custom colors