filamentphp 用了一段时间技巧分享

Logo 使用视图模版

$panel->brandLogo(
    fn () => view(
        LogoStyle::preview(
            // isRand: true // 可设置随机
            theme:LogoStyle::Deconstructed
        ),
        [
            'brandName' => $general->appName(),
            'primaryColor' => Color::Emerald
        ]
    )
)

底部版权试图

$panel->renderHook(
    'panels::footer',
    fn () => view('module-cores::layouts/footer')
);

更改主题色在中间件中设置


FilamentColor::register([
    'primary' => $this->settings->themeColor(),
]);

filamentphp 用了一段时间技巧分享

修改原icon

FilamentIcon::register([
    'actions::create-action.grouped' => 'heroicon-o-plus',
    'actions::view-action.grouped' => 'heroicon-o-eye',
    'actions::delete-action.grouped' => 'heroicon-o-trash',
    'forms::components.repeater.actions.delete' => 'heroicon-o-trash',
    'tables::actions.filter' => 'heroicon-o-funnel',
    'tables::actions.toggle-columns' => 'heroicon-o-view-columns'
]);

filamentphp 用了一段时间技巧分享

让字段支持多语言

Field::macro('translatable', function (bool $translatable = true, ?array $customLocales = null, ?array $localeSpecificRules = null) use ($supportedLocales) {
            if (! $translatable) {
                return $this;
            }

            $field = $this->getClone();

            $tabs = collect($customLocales ?? $supportedLocales)
                ->map(function ($entry) use ($field, $localeSpecificRules) {
                    $locale = $entry->slug;

                    $clone = $field
                        ->getClone()
                        ->name("{$field->getName()}.{$locale}")
                        ->label($field->getLabel())
                        ->statePath("{$field->getStatePath(false)}.{$locale}");

                    if ($localeSpecificRules && isset($localeSpecificRules[$locale])) {
                        $clone->rules($localeSpecificRules[$locale]);
                    }

                    return Tabs\Tab::make($locale)
                        ->label($entry->label)
                        ->schema([$clone]);
                })
                ->toArray();

            $tabsField = TranslateFormTags::make('translations')
                ->tabs($tabs);

            return $tabsField;
        });

使用


TextInput::make('name')->translatable()

效果

filamentphp 用了一段时间技巧分享

Modal 背景模糊

在你的theme.css 加入


.fi-modal-close-overlay{
    @apply backdrop-blur-sm;
}

效果

filamentphp 用了一段时间技巧分享

统一时间格式


// Form
$setting = app(GeneralSettings::class);

DateTimePicker::configureUsing(function (DateTimePicker $datetime) use ($setting): void {
    $datetime->timezone($setting->timezone())
        ->format($setting->datetimeFormat());
});

// Table 

Table::$defaultCurrency = $this->settings->currency();
Table::$defaultDateDisplayFormat = $this->settings->dateFormat();
Table::$defaultTimeDisplayFormat = $this->settings->timeFormat();
Table::$defaultDateTimeDisplayFormat = $this->settings->datetimeFormat();

2024-09-14

统一设置 translateLabel 自动翻译 Label

foreach ([Field::class, BaseFilter::class, Placeholder::class, Column::class, Entry::class] as $component) {
            /* @var Configurable $component */
            $component::configureUsing(function (Component $translatable): void {
                $translatable->translateLabel();
            });
        }

使用 enum 创建 label 和 颜色 icon 图标

use Illuminate\Support\HtmlString;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasLabel;

/**
 * GB/T 2261.1-2003
 *
 * @link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=0FC942D542BC6EE3C707B2647EF81CD8
 */
enum GenderStatus: int implements HasLabel, HasColor, HasIcon
{
    case Unknown = 0;

    case Male = 1;

    case Female = 2;

    case Notspecified = 9;

    public function getLabel(): ?string
    {
        return match($this) {
            static::Unknown => __('ofcold-cores::components/gender.unknown.label'),
            static::Male => __('ofcold-cores::components/gender.male.label'),
            static::Female => __('ofcold-cores::components/gender.female.label'),
            static::Notspecified => __('ofcold-cores::components/gender.notspecified.label'),
        };
    }

    public function getColor(): ?string
    {
        return match($this) {
            static::Unknown => 'yellow',
            static::Male => 'info',
            static::Female => 'fuchsia',
            static::Notspecified => 'gray',
        };
    }

    public function getIcon(): ?string
    {
        return ' you icon name'
    }
}

filamentphp 用了一段时间技巧分享

更多慢慢更新中….

本作品采用《CC 协议》,转载必须注明作者和本文链接
Ryan
Mumujin
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 8

默认色调不好看,改的这个可以

7个月前 评论

:see_no_evil: Filament 太好用了,前几天刚交付了一个小项目,工期一共7天,两天写后天五天写接口。

7个月前 评论

建议把filamentphp的文档搬到社区来

7个月前 评论
PHP-Coder 7个月前

filamentphp 有什么特色?

7个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!