Виджет плагина в Filament
Давайте добавим виджет плагина.
Блок с короткой
фразой появится
на
/admin,
если register
передаст панели
класс виджета.
Виджет GreetingWidget
уже рисует приветствие
в своём шаблоне.
Добавим его
в цепочку BlogPlugin.php
через widgets:
<?php
namespace App\Filament\Plugins;
use App\Filament\Pages\ReportPage;
use App\Filament\Resources\Posts\PostResource;
use App\Filament\Widgets\GreetingWidget;
use Filament\Contracts\Plugin;
use Filament\Panel;
class BlogPlugin implements Plugin
{
protected ?string $color = null;
public function getId(): string
{
return 'blog';
}
public static function make(): static
{
return app(static::class);
}
public function color(string $color): static
{
$this->color = $color;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function register(Panel $panel): void
{
$panel
->pages([
ReportPage::class,
])
->resources([
PostResource::class,
])
->widgets([
GreetingWidget::class,
]);
}
public function boot(Panel $panel): void
{
}
}
?>
Главный экран панели подхватит виджет автоматически: отдельная строка в провайдере для блока не понадобится.
Пусть плагин сам поставит блок с фразой на главный экран.