Image column
简介
表格中也可以基于列状态中的路径渲染图片:
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
此例中,avatar 状态值为 users/avatars/4281246003439.jpg,这是相对于存储磁盘根目录的路径。存储磁盘在配置文件中定义,默认为 local。你可以设置 FILESYSTEM_DISK 环境变量来修改它。
此外,该状态值也可以是图片的绝对 URL 路径,如 https://example.com/images/avatar.jpg。

设置 alt 文本
你应该为图片设置描述性的 alt 文本,以便屏幕阅读器用户能够理解每张图片展示的内容。请使用 alt() 方法:
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
->alt('User avatar')
除了允许静态值之外,alt() 方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中,包括当前图片的状态 $state。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Column | Filament\Tables\Columns\Column | $column | The current column instance. |
| Livewire | Livewire\Component | $livewire | The Livewire component instance. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current table row. |
| Row loop | stdClass | $rowLoop | The <a href="https://laravel.com/docs/blade#the-loop-variable" target="_blank">row loop</a> object for the current table row. |
| State | mixed | $state | The current value of the column, based on the current table row. |
| Table | Filament\Tables\Table | $table | The current table instance. |
如果你未设置任何 alt 文本,该图像将以空的 alt 属性进行渲染,这向辅助阅读表明该图像属于装饰性内容。
NOTE
当图像链接到某个 URL 时,其 alt 文本将成为该链接的可访问名称。请务必为链接图像设置具有实际意义的 alt 文本,否则使用屏幕阅读器的用户将遇到一个没有名称的链接。
管理图片存储磁盘
默认存储磁盘在配置文件中定义,默认为 local。你也可以通过设置 FILESYSTEM_DISK 环境变量来更 改此设置。如果你希望使用非默认磁盘,可以向 disk() 方法传入自定义的磁盘名称:
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('header_image')
->disk('s3')
除了允许静态值之外,disk() 方法也可以接受函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.| Utility | Type | Parameter | Description |
|---|---|---|---|
| Column | Filament\Tables\Columns\Column | $column | The current column instance. |
| Livewire | Livewire\Component | $livewire | The Livewire component instance. |
| Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current table row. |
| Row loop | stdClass | $rowLoop | The <a href="https://laravel.com/docs/blade#the-loop-variable" target="_blank">row loop</a> object for the current table row. |
| State | mixed | $state | The current value of the column, based on the current table row. |
| Table | Filament\Tables\Table | $table | The current table instance. |
