Readouble

Laravel 10.x アップグレードガイド

影響度の高い変更High Impact Changes

影響度が中程度の変更Medium Impact Changes

影響度の低い変更Low Impact Changes

9.xから10.0へのアップグレードUpgrading to 10.0 from 9.x

アップデート見積もり時間:10分Estimated Upgrade Time: 10 Minutes

lightbulb Note: 私たちは、互換性のない変更を可能な限りすべて文書化するよう努力しています。これらの互換性のない変更の一部はフレームワークの不明瞭な部分であり、こうした変更の一部が実際にあなたのアプリケーションに影響を与える可能性があります。時間を節約したいですか?Laravel Shift を使用すると、アプリケーションのアップグレードを自動化できます。[!NOTE]
We attempt to document every possible breaking change. Since some of these breaking changes are in obscure parts of the framework only a portion of these changes may actually affect your application. Want to save time? You can use Laravel Shift[https://laravelshift.com/] to help automate your application upgrades.

依存パッケージのアップデートUpdating Dependencies

影響の可能性: 高いLikelihood Of Impact: High

PHP8.1.0必須PHP 8.1.0 Required

現バージョンのLaravelは、PHP8.1.0以上が必要です。Laravel now requires PHP 8.1.0 or greater.

Composer2.2.0必須Composer 2.2.0 Required

現バージョンのLaravelは、Composer2.2.0以上が必要です。Laravel now requires Composer[https://getcomposer.org] 2.2.0 or greater.

Composerの依存パッケージComposer Dependencies

アプリケーションのcomposer.jsonファイルにある、以下の依存パッケージを更新してください。You should update the following dependencies in your application's composer.json file:

  • laravel/framework^10.0laravel/framework to ^10.0
  • laravel/sanctum^3.2laravel/sanctum to ^3.2
  • doctrine/dbal^3.0doctrine/dbal to ^3.0
  • spatie/laravel-ignition^2.0spatie/laravel-ignition to ^2.0
  • laravel/passport^11.0 (アップグレードガイド)laravel/passport to ^11.0 (Upgrade Guide[https://github.com/laravel/passport/blob/11.x/UPGRADE.md])
  • laravel/ui^4.0laravel/ui to ^4.0

Sanctum2.xリリースシリーズから3.xへアップグレードする場合は、Sanctumアップグレードガイドを参照してください。If you are upgrading to Sanctum 3.x from the 2.x release series, please consult the Sanctum upgrade guide[https://github.com/laravel/sanctum/blob/3.x/UPGRADE.md].

さらに、PHPUnit10を使用したい場合は、アプリケーションのphpunit.xml設定ファイルの<coverage>セクションから、processUncoveredFiles属性を削除する必要があります。次に、アプリケーションのcomposer.jsonファイルで、以下の依存関係を更新します。Furthermore, if you wish to use PHPUnit 10[https://phpunit.de/announcements/phpunit-10.html], you should delete the processUncoveredFiles attribute from the <coverage> section of your application's phpunit.xml configuration file. Then, update the following dependencies in your application's composer.json file:

  • nunomaduro/collision^7.0nunomaduro/collision to ^7.0
  • phpunit/phpunit^10.0phpunit/phpunit to ^10.0

最後に、アプリケーションで使用しているその他のサードパーティパッケージを調べ、Laravel10のサポートに適したバージョンを確実に使用してください。Finally, examine any other third-party packages consumed by your application and verify you are using the proper version for Laravel 10 support.

最低安定度Minimum Stability

アプリケーションのcomposer.jsonファイルのminimum-stability設定をstableへ更新する必要があります。もしくは、minimum-stabilityのデフォルト値はstableなので、アプリケーションの composer.jsonファイルからこの設定を削除してください。You should update the minimum-stability setting in your application's composer.json file to stable. Or, since the default value of minimum-stability is stable, you may delete this setting from your application's composer.json file:

"minimum-stability": "stable",

アプリケーションApplication

Publicパスの結合Public Path Binding

影響の可能性: 低いLikelihood Of Impact: Low

アプリケーションでコンテナへpath.publicを結合し、「公開パス」をカスタマイズしている場合は、代わりに Illuminate\Foundation\Applicationオブジェクトが提供するusePublicPathメソッドを呼び出すようにコードを更新する必要があります。If your application is customizing its "public path" by binding path.public into the container, you should instead update your code to invoke the usePublicPath method offered by the Illuminate\Foundation\Application object:

app()->usePublicPath(__DIR__.'/public');

許可Authorization

registerPoliciesメソッドThe registerPolicies Method

影響の可能性: 低いLikelihood Of Impact: Low

AuthServiceProviderregisterPoliciesメソッドをフレームワークが自動的に呼び出すようになりました。したがって、アプリケーションのAuthServiceProviderbootメソッドから、このメソッドの呼び出しを削除できます。The registerPolicies method of the AuthServiceProvider is now invoked automatically by the framework. Therefore, you may remove the call to this method from the boot method of your application's AuthServiceProvider.

キャッシュCache

RedisキャッシュタグRedis Cache Tags

影響の可能性: 中程度Likelihood Of Impact: Medium

Cache::tags() は、Memcachedを使用しているアプリケーションにのみに推奨します。アプリケーションのキャッシュドライバとしてRedisを使用している場合は、Memcachedへ移行するか、別のソリューションの使用を検討すべきです。Usage of Cache::tags() is only recommended for applications using Memcached. If you are using Redis as your application's cache driver, you should consider moving to Memcached or using an alternative solution.

データベースDatabase

データベース構文Database Expressions

影響の可能性: 中程度Likelihood Of Impact: Medium

データベースの「構文」(通常は DB::raw により生成)は、将来的に追加機能を提供するため、Laravel10.xで書き直しました。特に、構文の素の文字列の値は、構文のgetValue(Grammar $grammar)メソッドで取得する必要があります。(string)を使う構文から文字列へのキャストは、既にサポートしていません。Database "expressions" (typically generated via DB::raw) have been rewritten in Laravel 10.x to offer additional functionality in the future. Notably, the grammar's raw string value must now be retrieved via the expression's getValue(Grammar $grammar) method. Casting an expression to a string using (string) is no longer supported.

**通常、これはエンドユーザーのアプリケーションには無影響です。**しかし、もしアプリケーションで(string)を使用してデータベース式を文字列へ手作業でキャストしたり、構文に対して__toStringメソッドを直接呼び出している場合は、代わりにgetValueメソッドを呼び出すようにコードを更新する必要があります。Typically, this does not affect end-user applications; however, if your application is manually casting database expressions to strings using (string) or invoking the __toString method on the expression directly, you should update your code to invoke the getValue method instead:

use Illuminate\Support\Facades\DB;

$expression = DB::raw('select 1');

$string = $expression->getValue(DB::connection()->getQueryGrammar());

クエリ例外コンストラクタQuery Exception Constructor

影響の可能性: かなり低いLikelihood Of Impact: Very Low

Illuminate\Database\QueryExceptionのコンストラクターで、文字列の接続名を最初の引数に取るようにしました。アプリケーションがこの例外を手作業で投げている場合は、それに応じてコードを調整する必要があります。The Illuminate\Database\QueryException constructor now accepts a string connection name as its first argument. If your application is manually throwing this exception, you should adjust your code accordingly.

ULIDカラムULID Columns

影響の可能性: 低いLikelihood Of Impact: Low

マイグレーションで、ulidメソッドを引数なしで呼び出すと、カラムはulidという名前になります。Laravelの以前のリリースでは、引数なしでこのメソッドを呼び出すと、誤ってuuidという名前のカラムが作成されていました。When migrations invoke the ulid method without any arguments, the column will now be named ulid. In previous releases of Laravel, invoking this method without any arguments created a column erroneously named uuid:

$table->ulid();

ulidメソッドを呼び出すとき、明示的にカラム名を指定するには、そのカラム名をメソッドへ渡してください。To explicitly specify a column name when invoking the ulid method, you may pass the column name to the method:

$table->ulid('ulid');

EloquentEloquent

モデルの"Dates"プロパティModel "Dates" Property

影響の可能性: 中程度Likelihood Of Impact: Medium

Eloquentモデルで非推奨になっていた$datesプロパティを削除しました。アプリケーションでは、$castsプロパティを使用する必要があります。The Eloquent model's deprecated $dates property has been removed. Your application should now use the $casts property:

protected $casts = [
    'deployed_at' => 'datetime',
];

多言語化Localization

LanguageディレクトリThe Language Directory

影響の可能性: なしLikelihood Of Impact: None

既存のアプリケーションには関係ありませんが、Laravelアプリケーションのスケルトンは、langディレクトリをデフォルトで用意しなくなりました。代わりに、新しいLaravelアプリケーションを書く際には、lang:publish Artisanコマンドを使用してリソース公開してください。Though not relevant to existing applications, the Laravel application skeleton no longer contains the lang directory by default. Instead, when writing new Laravel applications, it may be published using the lang:publish Artisan command:

php artisan lang:publish

ログLogging

Monolog3Monolog 3

影響の可能性: 中程度Likelihood Of Impact: Medium

LaravelのMonolog依存バージョンをMonolog3.xへ更新しました。アプリケーション内でMonologと直接やりとりする場合は、Monologのアップグレードガイドを確認する必要があります。Laravel's Monolog dependency has been updated to Monolog 3.x. If you are directly interacting with Monolog within your application, you should review Monolog's upgrade guide[https://github.com/Seldaek/monolog/blob/main/UPGRADE.md].

BugSnagやRollbarなどのサードパーティのログサービスを使用している場合、それらのサードパーティのパッケージをMonolog3.xとLaravel10.xをサポートするバージョンへアップグレードする必要がある場合があります。If you are using third-party logging services such as BugSnag or Rollbar, you may need to upgrade those third-party packages to a version that supports Monolog 3.x and Laravel 10.x.

キューQueues

The Bus::dispatchNow MethodThe Bus::dispatchNow Method

影響の可能性: 低いLikelihood Of Impact: Low

非推奨にしていたBus::dispatchNowdispatch_nowメソッドを削除しました。代わりに、アプリケーションでは、それぞれBus::dispatchSyncdispatch_syncメソッドを使用する必要があります。The deprecated Bus::dispatchNow and dispatch_now methods have been removed. Instead, your application should use the Bus::dispatchSync and dispatch_sync methods, respectively.

dispatch()ヘルパの戻り値The dispatch() Helper Return Value

影響の可能性: 低いLikelihood Of Impact: Low

Illuminate\Contracts\Queueを実装していないクラスで、dispatchを起動すると、以前はそのクラスのhandleメソッドの結果を返していました。しかし、これは Illuminate\Foundation\Bus\PendingBatchインスタンスを返すようになりました。以前の動作を再現するには、dispatch_sync()を使ってください。Invoking dispatch with a class that does not implement Illuminate\Contracts\Queue would previously return the result of the class's handle method. However, this will now return an Illuminate\Foundation\Bus\PendingBatch instance. You may use dispatch_sync() to replicate the previous behavior.

ルートRouting

ミドルウェアエイリアスMiddleware Aliases

影響の可能性: 条件によるLikelihood Of Impact: Optional

新しいLaravelアプリケーションでは、App\Http\Kernelクラスの$routeMiddlewareプロパティは、その目的をよりよく表すために$middlewareAliasesへ名前を変更しました。既存のアプリケーションでこのプロパティの名前を変更することは歓迎しますが、必須ではありません。In new Laravel applications, the $routeMiddleware property of the App\Http\Kernel class has been renamed to $middlewareAliases to better reflect its purpose. You are welcome to rename this property in your existing applications; however, it is not required.

レート制限の戻り値Rate Limiter Return Values

影響の可能性: 低いLikelihood Of Impact: Low

RateLimiter::attemptメソッドを呼び出すと、指定したクロージャが返す値をメソッドからも返すようにしました。何も返さないかnullを返すと、attemptメソッドはtrueを返します。When invoking the RateLimiter::attempt method, the value returned by the provided closure will now be returned by the method. If nothing or null is returned, the attempt method will return true:

$value = RateLimiter::attempt('key', 10, fn () => ['example'], 1);

$value; // ['example']

Redirect::homeメソッドThe Redirect::home Method

影響の可能性: かなり低いLikelihood Of Impact: Very Low

非推奨だったRedirect::homeメソッドを削除しました。代わりに、アプリケーションでは明示的に名付けたルートへリダイレクトする必要があります。The deprecated Redirect::home method has been removed. Instead, your application should redirect to an explicitly named route:

return Redirect::route('home');

テストTesting

サービスのモックService Mocking

影響の可能性: 中程度Likelihood Of Impact: Medium

非推奨だったMocksApplicationServicesトレイトをフレームワークから削除しました。このトレイトはexpectsEventsexpectsJobsexpectsNotificationsといったテストメソッドを提供していました。The deprecated MocksApplicationServices trait has been removed from the framework. This trait provided testing methods such as expectsEvents, expectsJobs, and expectsNotifications.

もしあなたのアプリケーションでこれらのメソッドを使用するなら、それぞれEvent::fakeBus::fakeNotification::fakeへ移行することをお勧めします。フェイクを使ったモックについては、フェイクしようとしているコンポーネントの対応するドキュメントで詳しく説明されています。If your application uses these methods, we recommend you transition to Event::fake, Bus::fake, and Notification::fake, respectively. You can learn more about mocking via fakes in the corresponding documentation for the component you are attempting to fake.

バリデーションValidation

クロージャバリデーションルールメッセージClosure Validation Rule Messages

影響の可能性: かなり低いLikelihood Of Impact: Very Low

クロージャベースのカスタムバリデーションルールを書くとき、$failコールバックを複数回呼び出すと、前のメッセージを上書きする代わりに、メッセージを配列へ追加するようになりました。通常、これはアプリケーションに影響を与えることはありません。When writing closure based custom validation rules, invoking the $fail callback more than once will now append the messages to an array instead of overwriting the previous message. Typically, this will not affect your application.

加えて、$failコールバックはオブジェクトを返すようになりました。これまでバリデーションクロージャの戻り値の型をタイプヒントしていた場合は、タイプヒントを更新する必要があります。In addition, the $fail callback now returns an object. If you were previously type-hinting the return type of your validation closure, this may require you to update your type-hint:

public function rules()
{
    'name' => [
        function ($attribute, $value, $fail) {
            $fail('validation.translation.key')->translate();
        },
    ],
}

バリデーションメッセージとクロージャルールValidation Messages and Closure Rules

影響の可能性: かなり低いLikelihood Of Impact: Very Low

以前は、クロージャベースのバリデーションルールへ注入する、$failコールバックに配列を指定し、個別のキーへ失敗メッセージを割り当て可能でした。しかし、現行では、第1引数にキー、第2引数に失敗メッセージを指定する必要があります。Previously, you could assign a failure message to a different key by providing an array to the $fail callback injected into Closure based validation rules. However, you should now provide the key as the first argument and the failure message as the second argument:

Validator::make([
    'foo' => 'string',
    'bar' => [function ($attribute, $value, $fail) {
        $fail('foo', 'Something went wrong!');
    }],
]);

フォームリクエストのafterメソッドForm Request After Method

影響の可能性: かなり低いLikelihood Of Impact: Very Low

フォームリクエスト内でafterメソッドは、Laravelの予約語にしました。フォームリクエストでafterメソッドを定義している場合は、Laravelのフォームリクエストの新しい機能である「バリデーションのafter」を利用するために、このメソッドの名前を変更するか、修正する必要があります。Within form requests, the after method is now reserved by Laravel[https://github.com/laravel/framework/pull/46757]. If your form requests define an after method, the method should be renamed or modified to utilize the new "after validation" feature of Laravel's form requests.

その他Miscellaneous

laravel/laravel GitHubリポジトリの変更点をご覧いただくこともお勧めします。これらの変更の多くは必須ではありませんが、これらのファイルをあなたのアプリケーションと同期させておくとよいでしょう。これらの変更のいくつかは、このアップグレードガイドでカバーしていますが、設定ファイルやコメントの変更など、他のものはカバーしていません。We also encourage you to view the changes in the laravel/laravel GitHub repository[https://github.com/laravel/laravel]. While many of these changes are not required, you may wish to keep these files in sync with your application. Some of these changes will be covered in this upgrade guide, but others, such as changes to configuration files or comments, will not be.

GitHubのソース比較ツールで簡単に変更点を確認し、どのアップデートが自分にとって重要かを選択できます。ただし、GitHubソース比較ツールで表示される変更点の多くは、当オーガニゼーションがPHPネイティブ型を採用したことによるものです。これらの変更は後方互換性があり、Laravel 10への移行時に採用するかは任意です。You can easily view the changes with the GitHub comparison tool[https://github.com/laravel/laravel/compare/9.x...10.x] and choose which updates are important to you. However, many of the changes shown by the GitHub comparison tool are due to our organization's adoption of PHP native types. These changes are backwards compatible and the adoption of them during the migration to Laravel 10 is optional.

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作