You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在FilamentPHP中根据模型属性给页面标题加星形图标?

在FilamentPHP页面标题中根据模型属性添加Heroicon图标

你可以通过返回HtmlString在标题中嵌入Heroicon星形图标,替代原来的文字标记。修改后的代码如下:

use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;

public function getTitle(): string | Htmlable
{
    $title = $this->record->name;

    if ($this->record->is_favorite) {
        // 嵌入Heroicon星形图标,可通过class调整样式
        $title .= ' <x-heroicon-o-star class="inline-block w-4 h-4 text-yellow-500 ml-1" />';
    }

    return new HtmlString($title);
}

关键说明:

  • 用HtmlString包裹内容,避免Filament转义HTML代码,确保图标正常渲染
  • 借助Filament内置的Blade组件<x-heroicon-o-star>直接调用图标,通过class属性可自定义图标大小、颜色和间距(示例中设置了黄色、4px尺寸和右侧间距)
  • 逻辑和原代码保持一致:仅当模型的is_favorite属性为true时,才在标题后添加图标

内容的提问来源于stack exchange,提问作者nvcleemp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 01:19:58