Twinkle
Laravel BoostとMCPはほぼ理解
Boostで紛らわしいのはPhpStormとはJunieのことでプラグインで他のツールを使ってる場合は選んではいけない。
GitHub Copilotプラグインを使っているならこれ。
https://github.com/invokable/laravel-boost-phpstorm-copilot
「エディター・IDEの選択=MCP設定ファイルの選択(McpClientinterface)」と「ガイドラインの選択(Agentinterface)」の2段階ある。
MCPサーバー機能はphp-mcpからLaravel公式のlaravel/mcpに書き換えても問題なく動いてる。
Laravelで作るならMCPサーバーはremoteのほうが使い方も簡単だろうけどlocalも作ることはできる。
boostはlocalかつプロジェクト内で動かすので難しくなっている。
Eagerローディング(Eager Loading)
LaravelのEagerローディングは、データ取得を簡素化する強力なリレーションシップ機能です。
特徴
Eagerローディングを使用すると、with()メソッドを使って関連データを一度に取得できます。これにより「N+1問題」を防ぎ、データベースクエリの数を劇的に削減できます。
例
// N+1問題が発生する場合
$posts = Post::all();
foreach ($posts as $post) {
echo $post->author->name; // 投稿ごとにクエリ実行
}
// Eagerローディングを使用(推奨)
$posts = Post::with('author')->get();
foreach ($posts as $post) {
echo $post->author->name; // たった2つのクエリで完了
}
メリット
- データベースクエリの数を最小化
- アプリケーションのパフォーマンス向上
- シンプルで読みやすいコード
- 複数の関連データも同時に取得可能(
with(['author', 'comments']))
laravel/laravel v12.10.0
https://github.com/laravel/laravel/releases/tag/v12.10.0
Laravel のリリースノートに background ドライバーが追加されました。
laravel/framework v12.37.0
https://github.com/laravel/framework/releases/tag/v12.37.0
リリースノート要約
files()とdirectories()関数にカスタム「深さ」パラメータを渡せるようになったEnumerateValues::value()がオブジェクトをサポートし、負の値を返すように改善- 重複ロジックを再利用可能な別のメソッドに移動
- 未公開の
data_hasヘルパーをリファクタリング - キャッシュフェイルオーバードライバーに関する詳細説明を追加
data_hasの空チェックを修正- 空文字列チェック前にトリムを使用するよう修正
- キューフェイルオーバードライバーの詳細説明を追加
- フェイルオーバーとラウンドロビンのメーラー詳細を追加
- 未使用変数を削除
Factory@insert()メソッドを追加- Windows上でのScheduleRunCommandTestの失敗を、OS固有の成功コマンドを使って修正
- StrとStringableに
ucwordsを追加 Connection@listen()のドキュメントブロックを改善- 通知の接続/キューへの正しいフォールバックを修正
- DatabaseServiceProviderで未使用のクロージャパラメータを削除
- RedisクラスターのキューテストにQUEUE_CONNECTIONを追加
- ArtisanServiceProviderで未使用パラメータを削除
- Fileルールでカスタムバリデーションメッセージが機能するよう修正
- JSONスキーマの改善
- キュージョブをバックグラウンド処理する機能を追加
- ChainedBatchがラップされたバッチのキューと接続を維持するよう修正
Contextual Binding for Better Dependency Injection
When working with Laravel's service container, you can use contextual binding to inject different implementations of an interface based on which class is requesting it:
$this->app->when(PhotoController::class)
->needs(StorageInterface::class)
->give(CloudStorage::class);
$this->app->when(DocumentController::class)
->needs(StorageInterface::class)
->give(LocalStorage::class);
This approach allows you to maintain clean dependency injection in your classes while letting the container handle the complexity of determining which implementation to provide. Your controllers can simply type-hint the interface in their constructors, and Laravel will automatically inject the appropriate implementation based on the context.
livewire/livewire v4.0.0-beta.2
https://github.com/livewire/livewire/releases/tag/v4.0.0-beta.2
変更点要約
prepareViewsForCompilationUsingを追加- 遅延読み込みのドキュメントで
lazy_placeholderをcomponent_placeholderに置き換え - ビュー関数へのデータ受け渡しの修正
- スネークケースのコンポーネントパラメータの修正
- composer fixtures の問題を修正
- 内部リンクを v4 に更新
laravel/framework v12.36.1
https://github.com/laravel/framework/releases/tag/v12.36.1
- Laravel 12.xでは、version_compare()関数を使用する際に常にoperator引数を使用するように変更された。
- Filesystem クラスに allDirectories() メソッドが追加された。
- EnumerateValues::value() で負の値をサポートする変更が一度追加されたが、その後取り消された。
Laravel Boost Custom CodeEnvironment for GitHub Copilot CLI
laravel/framework v12.36.0
https://github.com/laravel/framework/releases/tag/v12.36.0
リリースノート要約
- Http\Client\Batchのコンストラクタからreturn voidを削除
- ファイルキャッシュロックキーの名前空間化
- コンストラクタから@returnタグを削除
- 不足していた@throwsアノテーションを追加
- セッターでのチェーン呼び出しを許可
- S3ファイルシステムパスの二重プレフィックス問題を修正
- Uriビルダーメソッドのテストを追加
- jsonSerializeメソッドをmatch式を使用してリファクタリング
- リダイレクトレスポンスで同一オリジンを強制
- Eloquentコレクションに「setAppends」と「withoutAppends」メソッドを追加
- 多数のキーがある場合のRedisキャッシュタグフラッシュ時のバッファオーバーフロー修正
- バリデーターメッセージのプレースホルダーの大文字化を許可
- Model::__sleep()の戻り値からプロパティフックを除外
- Http::poolとHttp::batchに同時実行制御を追加
Laravel Boostの使いにくさが完全に解決した
Copilot CLIに--additional-mcp-configが追加されてもエラーで使えなかったけどやっと正しい設定方法が判明。
Laravel Boostが作るデフォルトのjsonがどういう環境を前提にしてるのか分からないほど間違ってる。
GitHub Copilot CLIでのLaravel Boost使用方法
https://github.com/orgs/invokable/discussions/22
The tap() Method in Laravel
One of Laravel's lesser-known yet powerful methods is tap(). This elegant utility allows you to work with a value, perform actions on it, and then return the original value regardless of the callback's return value.
The method signature is simple:
tap($value, $callback = null)
This helper is particularly useful when you want to perform actions on an object and continue chaining methods without breaking the flow. For example:
return tap(new User, function ($user) {
$user->name = 'Taylor';
$user->email = 'taylor@example.com';
$user->save();
});
Instead of assigning the user to a variable, performing operations, and then returning it, tap() handles this cleanly in one expression.
When working with collections, it's invaluable for performing side effects while maintaining chainability:
return $users->filter(function ($user) {
return $user->isActive();
})->tap(function ($filteredUsers) {
Log::info('Filtered users: ' . $filteredUsers->count());
})->map(function ($user) {
return $user->profile;
});
This simple method can significantly clean up your code by reducing variable assignments and improving readability in complex operations.
laravel/framework v12.35.1
https://github.com/laravel/framework/releases/tag/v12.35.1
リリースノート要約
- セッションに以前のルート名を保存する機能を追加
- 最小限の例外ビューのCSSを更新
- HTTPバッチ結果がリクエストと同じ順序で返されるように修正
Batchクラス内のResponse名前空間を修正NamedScopeをScopeにリネーム- S3アダプターが正しいパス区切り文字を使用するように修正し、関連テストを更新
- BootcampをLaravel Learnに置き換え
QueueFailedOverイベントに例外を渡すよう修正- サーバーワーカーが尊重できない場合に警告を追加
- フェイルオーバー使用時にキャッシュイベントで基盤となるストア名を発行するよう修正
laravel/framework v12.35.0
https://github.com/laravel/framework/releases/tag/v12.35.0
- すべてのデータベースで
DB::update()をサブクエリで使用できない問題を修正 - AnyOf、Can、Enumでカスタムバリデーションメッセージが動作するように修正
- ResolvesDumpSourceでNeovimエディタをサポート
- 例外発生時にクリック可能なファイル参照を追加
- クエリツールチップで改行を表示
- SQS FIFOとフェアキューのmessageGroup()メソッドサポートを追加
- MariaDBで
json_value()を使用するように変更 - 遅延キューを実装
- 整数バリデーションのPHPドキュメントタイプ注釈を修正
- Number::format()に可算オブジェクトを渡す際の問題を修正
- Route::middlewareでnullを受け入れるように更新
- ダンプソースのhrefで最初のbasePathのみを置換するように修正
- Encrypterクラスに不足していた@throws注釈を追加
- Database Connectionクラスに不足していた@throws注釈を追加
- テスト改善
- 属性値が配列の場合のvalidateDigitsでTypeErrorを防止
- 例外レンダラーのviteを7.1.6から7.1.11にアップグレード
- フェイルオーバーキャッシュを実装
- イベントの遅延時に未解析のイベントとペイロードを収集するように修正
Contextual Binding for Improved Dependency Injection in Laravel
When you need different implementations of an interface based on the class that's requesting it, use contextual binding:
$this->app->when(PhotoController::class)
->needs(StorageInterface::class)
->give(CloudStorage::class);
$this->app->when(DocumentController::class)
->needs(StorageInterface::class)
->give(LocalStorage::class);
This allows you to inject different implementations of the same interface based on context, making your dependency injection more flexible while maintaining type-hinting throughout your application. Configure these bindings in your service providers to keep your controllers clean and focused on their responsibilities.
laravel/framework v12.34.0
https://github.com/laravel/framework/releases/tag/v12.34.0
リリースノート要約
- PostgreSQLの仮想カラム機能の追加
- Viteのアセットパス生成を継承で拡張可能に変更
- FakeInvokedProcessにwaitUntilメソッドを追加
- Zed、Trae、Windsurf、Kiro、Fleetエディタのサポートを追加
- エラーページのアクセシビリティ向上のためテキスト色を更新
- 構文ハイライト付きクエリのテキスト切り詰め問題を修正
- メールルールのヘルパーメッセージを修正
- Auth::login()中にセッションを再生成するように変更
- HTTP batchにdeferメソッドを追加
- キューのフェイルオーバー機能のプロトタイプ
- throw_if関数でクロージャーをサポート
- PHPUnit 12.4のサポート追加
- PHP 8.5のnull配列インデックス非推奨に関する修正
- マルチバイトロケールでのスケジュールリストCLIフォーマットを修正
- その他コードのフォーマット修正、ドキュメントブロックの改善