😸

Filamentをv2からv3にアップグレードした時の備忘録

2023/12/05に公開

この記事について

  • この記事はLaravel Advent Calendar 2023 5日目の投稿です
  • Filamentのバージョンを2系から3系へのアップグレードしました
  • 個人的に少し詰まった部分もあったので、それも含めて手順についておさらいしたいと思います

バージョン2系から3系へのアップグレード

https://filamentphp.com/docs/3.x/panels/upgrade-guide

手順は公式ドキュメントの「Upgrading automatically」に沿って進めていきます。
ドキュメントのコマンド と、 コマンドの実行結果に表示されたコマンド を実行していきます。

まずは下記コマンドを実行します。

composer require filament/upgrade:"^3.0-stable" -W --dev

完了後、vendor/bin/filament-v3 というスクリプトが生成されるので、これを実行します。
実行中に y/nの入力を求められるので、yを入力します。

# vendor/bin/filament-v3 
                         
   Filament v3 Upgrade   
                         

Welcome to the Filament v3 upgrade process! 
This script will attempt to handle most of the breaking changes for you. 
If you have any questions, please reach out to us on Discord or GitHub.

To begin, please ensure that you are using a version control system such as Git. 
We will make changes directly to your files, and you will need to be able to revert them if something goes wrong. 
Please commit any changes you have made to your project before continuing.

Are you ready to continue? y/n y
~省略~
Finished processing /app.

Now you're ready to update your Composer dependencies!

First require new versions of Filament packages: 
composer require filament/filament:"^3.0-stable" -W --no-update

If you have any 3rd party plugins that need to be upgraded, you should bump those dependencies as well. 

And then run: 
composer update

If you have any questions, please reach out to us on Discord or GitHub.

実行後、上記のようなメッセージが表示されます。

# composer require filament/filament:"^3.0-stable" -W --no-update
# composer update

この2つのコマンドを実行するようにという内容ですので、実行します。

# composer require filament/filament:"^3.0-stable" -W --no-update
./composer.json has been updated
# composer update
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
~省略~
99 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

No security vulnerability advisories found

実行後は、また公式ドキュメントに従って下記コマンドを実行することで、アップグレードが完了します。

# php artisan filament:install
  ⇂ public/js/filament/forms/components/color-picker.js  
  ⇂ public/js/filament/forms/components/date-time-picker.js  
  ⇂ public/js/filament/forms/components/file-upload.js  
~省略~
   INFO  Successfully upgraded!  

 ┌ All done! Would you like to show some love by starring the Filament repo on GitHub? ┐
 │ No                                                                                  │
 └─────────────────────────────────────────────────────────────────────────────────────┘

実行中にyesの入力を求められるので入力します。

# composer remove filament/upgrade
filament/upgrade could not be found in require but it is present in require-dev
Do you want to remove it from require-dev [yes]? yes
./composer.json has been updated
~省略~
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

No security vulnerability advisories found

ここまで実行すると、アップグレードが完了します。

アップグレードの確認

一番わかりやすい箇所として、アップグレード後にFilamentにログインすると、ログアウトリンクの上の部分で画面設定ができるようになっています。



左から「ライトモード」、「ダークモード」、「PCのシステム設定と同じにする」といった感じで選択できます。
(デフォルトはPCと同じ設定になっています) 

また、アップグレード後にはいろいろと機能が追加されており、個人的には TableBuildertable メソッドで使える searchPlaceholder で、テーブルの検索欄のプレースホルダーが変更できるのが地味に嬉しかったです。

https://filamentphp.com/docs/3.x/tables/columns/getting-started#customizing-the-table-search-field-placeholder

修正前

修正後

関連記事

EGSTOCK,Inc.

Discussion