自定义 Entry
简介
你可以创建你自己的自定义条目(Entry)类及视图,它可以在整个应用中进行重用,甚至可以将其作为插件发布到社区。
你可以创建自定义条目(Entry)类及视图,请要使用如下命令:
php artisan make:filament-infolist-entry AudioPlayerEntry
该命令将创建以下组件类:
use Filament\Infolists\Components\Entry;
class AudioPlayerEntry extends Entry
{
protected string $view = 'filament.infolists.components.audio-player-entry';
}
同时生成一个视图文件:resources/views/filament/infolists/components/audio-player-entry.blade.php
。
NOTE
Filament 信息列表条目不是 Livewire 组件。在条目类中定义公共属性和方法不会使之在 Blade 视图中可访问到。
在 Blade 视图中访问条目状态
在 Blade 视图中,你可以使用 $getState()
函数访问条目的状态值:
<x-dynamic-component
:component="$getEntryWrapperView()"
:entry="$entry"
>
{{ $getState() }}
</x-dynamic-component>
在 Blade 视图中访问其他组件的状态
在 Blade 视图中,你可以使用 $get()
函数访问 Schema 中其他组件的状态值:
<x-dynamic-component
:component="$getEntryWrapperView()"
:entry="$entry"
>
{{ $get('email') }}
</x-dynamic-component>
TIP
Unless a form field is reactive, the Blade view will not refresh when the value of the field changes, only when the next user interaction occurs that makes a request to the server. If you need to react to changes in a field's value, it should be live()
.