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(),
]);
修改原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'
]);
让字段支持多语言
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()
效果
Modal 背景模糊
在你的theme.css 加入
.fi-modal-close-overlay{
@apply backdrop-blur-sm;
}
效果
统一时间格式
// 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'
}
}
更多慢慢更新中….
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: