oriondevelops/filament-greeter

一个用于问候用户的Filament插件。

v0.2.0 2024-09-26 18:43 UTC

This package is auto-updated.

Last update: 2024-09-27 22:44:32 UTC


README

Latest Version on Packagist Total Downloads

这个Filament插件是nova-greeter的兄弟插件,它扩展了默认的账户小部件,让您

  • 为自己和用户设置花哨的头衔
  • 添加自定义操作
  • 更改欢迎信息
  • 更改头像大小
  • 禁用头像

example-daenerys

安装

您可以通过composer安装此包

composer require oriondevelops/filament-greeter

使用方法

您需要将插件与您首选的Filament面板提供商注册。这可以在您的PanelProvider中完成,例如AdminPanelProvider

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use Filament\Actions\Action;
use Orion\FilamentBackup\BackupPlugin;
use Orion\FilamentGreeter\GreeterPlugin;
use Orion\FilamentFeedback\FeedbackPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                BackupPlugin::make()
                    ->queue('monitors'),
                // ...    
                GreeterPlugin::make()
                    ->message('Welcome,')
                    ->name('Daenerys Targaryen')
                    ->title('The First of Her Name, the Unburnt, Queen of Meereen, Queen of the Andals and the Rhoynar and the First Men, Khalisee of the Great Grass Sea, Breaker of Chains and Mother of Dragons')
                    ->avatar(size: 'w-16 h-16', url: 'https://avatarfiles.alphacoders.com/236/236674.jpg')
                    ->action(
                        Action::make('action')
                            ->label('Buy more unsullied')
                            ->icon('heroicon-o-shopping-cart')
                            ->url('https://buyunsulliedonline.com')
                    )
                    ->sort(-1)
                    ->columnSpan('full'),
                // ...
                FeedbackPlugin::make()
                    ->sendResponsesTo(email: 'oriondevelops@gmail.com'),
            ])
    }
}

消息

->message(text: 'Welcome')

为了动态确定欢迎信息,您可以使用闭包

 ->message(text: fn() => auth()->user()->hasRole('Super Administrator') ? __('Welcome my lord') : __('Welcome'))

时间敏感问候

->timeSensitive(morningStart: 6, afternoonStart: 12, eveningStart: 17, nightStart: 22)

根据当前时间,问候信息将更改为“早上好”、“下午好”、“晚上好”或“晚安”。您可以选择省略小时参数以使用默认时间。

标题

->title(text: 'Administrator', enabled: true)

要基于用户更改标题,您可以使用闭包

->title(text: fn() => auth()->user()->title)

头像

设置用户头像

->avatar(size: 'lg', enabled: true),

操作

->action(
    Action::make('action')
        ->label('Buy more unsullied')
        ->icon('heroicon-o-shopping-cart')
        ->url('https://buyunsulliedonline.com')
)

示例

example-rand

GreeterPlugin::make()
    ->message('Welcome')
    ->name("Rand al'Thor")
    ->title("Dragon Reborn, Coramoor, Car'a'carn, He Who Comes With the Dawn, Shadowkiller, King of Illian, Lord of the Morning")
    ->avatar(size: 'w-16 h-16')
    ->columnSpan('full')
    ->action(
        Action::make('action')
            ->label('Reborn')
            ->color('danger')
            ->icon('heroicon-o-arrow-path')
            ->action(function () {
                Notification::make()
                    ->title('Reborn successfully')
                    ->success()
                    ->send();
            })
    ),

example-annatar

GreeterPlugin::make()
    ->message('Welcome')
    ->name("Annatar")
    ->action(
        Action::make('action')
            ->label('Gift a ring')
            ->color('warning')
            ->icon('heroicon-o-gift')
            ->action(function () {
                Notification::make()
                    ->title('Target deceived successfully')
                    ->warning()
                    ->send();
            })
    ),

example-no-avatar

GreeterPlugin::make()
    ->avatar(enabled: false),

example-dayne

GreeterPlugin::make()
    ->timeSensitive()
    ->name('Ser Arthur Dayne')
    ->title('Sword of the Morning')
    ->avatar(size: 'w-16 h-16')
    ->columnSpan('full')
    ->action(
        Action::make('action')
            ->label('Protect the Heir')
            ->icon('heroicon-o-shield-check')
            ->action(fn () => Notification::make()->title('You failed! You’ve been stabbed in the back.')->danger()->send())
    ),

贡献

请参阅CONTRIBUTING以获取详细信息。

安全性

请审查安全策略以了解如何报告安全漏洞。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件