LoginSignup
1
0

filament v3の新機能 パネルビルダーをチラ見

Last updated at Posted at 2023-12-10

概要

filament バージョン3からパネルビルダーと言う機能が追加されました。
どのような機能なのか紹介します。

内容

名前の通り管理パネルを複数用意できる機能です。
パネルAにはResourceAとResourceB、パネルBにはResourceCとResourceDとカスタムページA
と言った具合に切り分けできる機能です。
イメージ的にはこんな感じ

スクショを貼り付けてみます。URLに注目。
/admin//app/で表示されてるサイドメニューが異なります。
このようにルートによって使用するResourceクラスやカスタムページを調整できます。

image.png

image.png

どのように管理しているかと言うと、各パネルごとにパネルプロバイダークラスを作成し、そこで何のクラスを使うのかを定義します。
以下は/appのパネルプロバイダークラスです。

  • discoverResources
    • どのディレクトリ配下のResourceクラスを使用するかを定義する
  • discoverPages
    • どのディレクトリ配下のPageクラスを使用するかを定義する
  • discoverWidgets
    • どのディレクトリ配下のwidgetクラスを使用するかを定義する

こんな感じで、各パネルで何を利用するかを定義できます。詳しくはドキュメントへ

class AppPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->id('app')
            ->path('app')
            ->colors([
                'primary' => Color::Amber,
            ])
            ->discoverResources(in: app_path('Filament/App/Resources'), for: 'App\\Filament\\App\\Resources')
            ->discoverPages(in: app_path('Filament/App/Pages'), for: 'App\\Filament\\App\\Pages')
            ->pages([
                Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/App/Widgets'), for: 'App\\Filament\\App\\Widgets')
            ->widgets([
                Widgets\AccountWidget::class,
                Widgets\FilamentInfoWidget::class,
                PatientTypeOverview::class,
                TreatmentsChart::class
            ])
....
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0