重要度の高い変更High Impact Changes
重要度が中程度の変更Medium Impact Changes
6.xから7.0へのアップグレードUpgrading To 7.0 From 6.x
アップグレード見積もり時間:15分Estimated Upgrade Time: 15 Minutes
Note: {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.
私達は、互換性を失う可能性がある変更を全部ドキュメントにしようとしています。しかし、変更点のいくつかは、フレームワークの明確ではない部分で行われているため、一部の変更が実際にアプリケーションに影響を与えてしまう可能性があります。
Symfony5要件Symfony 5 Required
影響の可能性: 高いLikelihood Of Impact: High
Laravel7は裏で動作しているSymfonyコンポーネントを5.xへアップグレードしました。新しい最低限のコンパチブルバージョンもこれになりました。Laravel 7 upgraded its underlying Symfony components to the 5.x series, which is now also the new minimum compatible version.
PHP 7.2.5要件PHP 7.2.5 Required
影響の可能性: 低いLikelihood Of Impact: Low
新しいPHPの最低動作バージョンは7.2.5になりました。The new minimum PHP version is now 7.2.5.
依存パッケージのアップデートUpdating Dependencies
composer.json
ファイル中に指定されている以下のパッケージ依存を更新してください。Update the following dependencies
in your composer.json
file:
laravel/framework
を^7.0
へlaravel/framework
to^7.0
nunomaduro/collision
を^4.1
へnunomaduro/collision
to^4.1
phpunit/phpunit
を^8.5
へphpunit/phpunit
to^8.5
laravel/tinker
を^2.0
へlaravel/tinker
to^2.0
facade/ignition
を^2.0
へfacade/ignition
to^2.0
以下のファーストパーティ製パッケージは、Laravel7に対応する新しいメジャーリリースを出しました。どれか使用しているのであれば、それぞれのアップグレードガイドをLaravel7へのアップグレードの前にお読みください。The following first-party packages have new major releases to support Laravel 7. If there are any, read through their individual upgrade guides before upgrading:
- Browser Kit Testing v6.0Browser Kit Testing v6.0[https://github.com/laravel/browser-kit-testing/blob/master/UPGRADE.md]
- Envoy v2.0Envoy v2.0[https://github.com/laravel/envoy/blob/master/UPGRADE.md]
- Horizon v4.0Horizon v4.0[https://github.com/laravel/horizon/blob/master/UPGRADE.md]
- Nova v3.0Nova v3.0[https://nova.laravel.com/releases]
- Passport v9.0Passport v9.0[https://github.com/laravel/passport/blob/master/UPGRADE.md]
- Scout v8.0Scout v8.0[https://github.com/laravel/scout/blob/master/UPGRADE.md]
- Telescope v3.0Telescope v3.0[https://github.com/laravel/telescope/releases]
- Tinker v2.0Tinker v2.0[https://github.com/laravel/tinker/blob/2.x/CHANGELOG.md]
- UI v2.0 (No changes necessary)UI v2.0 (No changes necessary)
最後に、皆さんのアプリケーションで使用する他のサードパーティ製パッケージを調べ、Laravel7に対応するバージョンを使用していることを確認してください。Finally, examine any other third-party packages consumed by your application and verify you are using the proper version for Laravel 7 support.
Symfony5へのアップグレードSymfony 5 Related Upgrades
影響の可能性: 高いLikelihood Of Impact: High
Laravel7は、Symfonyコンポーネントの5.xシリーズを活用しています。このアップグレードを含め、いくつか細かいアプリケーションの修正が必要となります。Laravel 7 utilizes the 5.x series of the Symfony components. Some minor changes to your application are required to accommodate this upgrade.
最初に、アプリケーションのApp\Exceptions\Handler
クラスのreport
とrender
、shouldReport
、renderForConsole
メソッドは、Exception
インスタンスに代えThrowable
インターフェイスのインスタンスを受け取る必要があります。First,
the
report
,
render
,
shouldReport
,
and
renderForConsole
methods
of
your
application's
App\Exceptions\Handler
class
should
accept
instances
of
the
Throwable
interface
instead
of
Exception
instances:
use Throwable;
public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);
次に、session
設定ファイルのsecure
オプションをフォールバック値のnull
へ変更してください。Next,
please
update
your
session
configuration
file's
secure
option
to
have
a
fallback
value
of
null
:
'secure' => env('SESSION_SECURE_COOKIE', null),
Artisanの裏で動作しているSymfony Consoleはすべてのコマンドが整数値を返すことを期待しています。そのため値を返すすべてのコマンドは確実に整数を返してください。Symfony Console, which is the underlying component that powers Artisan, expects all commands to return an integer. Therefore, you should ensure that any of your commands which return a value are returning integers:
public function handle()
{
// 以前
return true;
// 以後
return 0;
}
認証Authentication
スカフォールドScaffolding
影響の可能性: 高いLikelihood Of Impact: High
すべての認証スカフォールドはlaravel/ui
リポジトリへ移動済みです。Laravelの認証スカフォールドを使用する場合は、このパッケージの^2.0
リリースをインストールしてください。すべての環境でこのパッケージをインストールしてください。アプリケーションのcomposer.json
ファイル中で以前にこのパッケージをrequire-dev
で依存指定していた時は、require
に移動する必要があります。All
authentication
scaffolding
has
been
moved
to
the
laravel/ui
repository.
If
you
are
using
Laravel's
authentication
scaffolding,
you
should
install
the
^2.0
release
of
this
package
and
the
package
should
be
installed
in
all
environments.
If
you
were
previously
including
this
package
in
the
require-dev
portion
of
your
application's
composer.json
file,
you
should
move
it
to
the
require
section:
composer require laravel/ui "^2.0"
TokenRepositoryInterface
The
TokenRepositoryInterface
影響の可能性: 低いLikelihood Of Impact: Low
Illuminate\Auth\Passwords\TokenRepositoryInterface
インターフェイスへrecentlyCreatedToken
メソッドを追加しました。このインターフェイスのカスタム実装を書いているときは、このメソッドを追加実装してください。A
recentlyCreatedToken
method
has
been
added
to
the
Illuminate\Auth\Passwords\TokenRepositoryInterface
interface.
If
you
are
writing
a
custom
implementation
of
this
interface,
you
should
add
this
method
to
your
implementation.
BladeBlade
component
メソッドThe
component
Method
影響の可能性: 中程度Likelihood Of Impact: Medium
Blade::component
メソッドはBlade::aliasComponent
へ名前を変えました。このメソッドの呼び出しを対応するように変更してください。The
Blade::component
method
has
been
renamed
to
Blade::aliasComponent
.
Please
update
your
calls
to
this
method
accordingly.
Bladeコンポーネントと"Blade x"Blade Components & "Blade X"
影響の可能性: 中程度Likelihood Of Impact: Medium
Laravel7はBlade「タグコンポーネント」のファーストパーティサポートを含んでいます。Bladeの組み込みタグコンポーネント機能を無効にしたい場合は、AppServiceProvider
のboot
メソッドでwithoutComponentTags
メソッドを呼び出してください。Laravel
7
includes
first-party
support
for
Blade
"tag
components".
If
you
wish
to
disable
Blade's
built-in
tag
component
functionality,
you
may
call
the
withoutComponentTags
method
from
the
boot
method
of
your
AppServiceProvider
:
use Illuminate\Support\Facades\Blade;
Blade::withoutComponentTags();
EloquentEloquent
addHidden
/addVisible
メソッドThe
addHidden
/
addVisible
Methods
影響の可能性: 低いLikelihood Of Impact: Low
ドキュメントに乗せなくなっていたaddHidden
とaddVisible
メソッドは削除しました。代わりにmakeHidden
とmakeVisible
メソッドを使用してください。The
undocumented
addHidden
and
addVisible
methods
have
been
removed.
Instead,
please
use
the
makeHidden
and
makeVisible
methods.
booting
/booted
メソッドThe
booting
/
booted
Methods
影響の可能性: 低いLikelihood Of Impact: Low
モデルの「起動(boot)」処理中で実行すべきロジックを便利に定義できる箇所を提供するため、booting
とbooted
メソッドがEloquentへ追加されました。この名前のモデルメソッドをすでに使っている場合は、今回追加した新しいメソッドと衝突するため、リネームが必要になります。The
booting
and
booted
methods
have
been
added
to
Eloquent
to
provide
a
place
to
conveniently
define
any
logic
that
should
execute
during
the
model
"boot"
process.
If
you
already
have
model
methods
with
these
names,
you
will
need
to
rename
your
methods
so
they
do
not
conflict
with
the
newly
added
methods.
データシリアライズDate Serialization
影響の可能性: 高いLikelihood Of Impact: High
Laravel7はEloquentモデル上でtoArray
かtoJson
メソッド使用時に、新しい日付シリアライズ形式を使用しています。シリアライズの日付形式にするため、CarbonのtoJson
メソッドを使用するようになりました。これはタイムゾーンと秒の小数部を含んだISO-8601準拠の日付です。さらにこの変更により、クライアントサイドの日付パースライブラリの統合とより良いサポートが実現できました。Laravel
7
uses
a
new
date
serialization
format
when
using
the
toArray
or
toJson
method
on
Eloquent
models.
To
format
dates
for
serialization,
the
framework
now
uses
Carbon's
toJSON
method,
which
produces
an
ISO-8601
compatible
date
including
timezone
information
and
fractional
seconds.
In
addition,
this
change
provides
better
support
and
integration
with
client-side
date
parsing
libraries.
以前のシリアライズされた日付形式は2019-12-02
20:01:00
でした。新しいシリアライズ済み日付形式は2019-12-02T20:01:00.283041Z
のようになります。ISO-8601日付は常にUTCで表現されることに注意してください。Previously,
dates
would
be
serialized
to
a
format
like
the
following:
2019-12-02
20:01:00
.
Dates
serialized
using
the
new
format
will
appear
like:
2019-12-02T20:01:00.283041Z
.
Please
note
that
ISO-8601
dates
are
always
expressed
in
UTC.
以前の振る舞いのままが好ましい場合は、モデルのserializeDate
メソッドをオーバーライドしてください。If
you
would
like
to
keep
using
the
previous
behavior
you
can
override
the
serializeDate
method
on
your
model:
use DateTimeInterface;
/**
* 配列/JSONシリアライズのためデータを準備する
*
* @param \DateTimeInterface $date
* @return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
{tip} This change only affects serialization of models and model collections to arrays and JSON. This change has no effect on how dates are stored in your database.
">Tip!! この変更はモデルとモデルコレクションの、配列とJSONへのシリアライズにだけ影響を及ぼします。この変更はデータベースに日付を保存する方法にはまったく影響しません。
FactoryタイプFactory Types
影響の可能性: 中程度Likelihood Of Impact: Medium
Laravel7では「ファクトリタイプ」機能を削除しました。この機能は2016年10月からドキュメントに記載していません。まだこの機能を利用している場合はより柔軟性が高いファクトリステートへアップグレードしてください。Laravel 7 removes the "factory types" feature. This feature has been undocumented since October 2016. If you are still using this feature, you should upgrade to factory states[/docs/{{version}}/database-testing#factory-states], which provide more flexibility.
getOriginal
メソッドThe
getOriginal
Method
影響の可能性: 低いLikelihood Of Impact: Low
$model->getOriginal()
メソッドはモデルで定義されるキャストとミューテタを反映するようにしました。以前のこのメソッドはキャストせず、元の値をそのまま返していました。元のままのキャストしない値を続けて取得したい場合は、代わりにgetRawOriginal
メソッドを使ってください。The
$model->getOriginal()
method
will
now
respect
any
casts
and
mutators
defined
on
the
model.
Previously,
this
method
returned
the
uncast,
raw
attributes.
If
you
would
like
to
continue
retrieving
the
raw,
uncast
values,
you
may
use
the
getRawOriginal
method
instead.
ルート結合Route Binding
影響の可能性: 低いLikelihood Of Impact: Low
Illuminate\Contracts\Routing\UrlRoutable
インターフェイスのresolveRouteBinding
メソッドは、$field
引数を取るようになりました。このインターフェイスを実装している場合は変更してください。The
resolveRouteBinding
method
of
the
Illuminate\Contracts\Routing\UrlRoutable
interface
now
accepts
a
$field
argument.
If
you
were
implementing
this
interface
by
hand,
you
should
update
your
implementation.
さらにIlluminate\Database\Eloquent\Model
クラスのresolveRouteBinding
メソッドも$field
引数を取るようになりました。このメソッドをオーバーライドしている場合は、この引数を受け取るように変更する必要があります。In
addition,
the
resolveRouteBinding
method
of
the
Illuminate\Database\Eloquent\Model
class
also
now
accepts
a
$field
parameter.
If
you
were
overriding
this
method,
you
should
update
your
method
to
accept
this
argument.
最後に、Illuminate\Http\Resources\DelegatesToResources
トレイトのresolveRouteBinding
メソッドでも$field
引数を取るようになりました。このメソッドをオーバーライドしている場合は、この引数を受け取るように変更する必要があります。Finally,
the
resolveRouteBinding
method
of
the
Illuminate\Http\Resources\DelegatesToResources
trait
also
now
accepts
a
$field
parameter.
If
you
were
overriding
this
method,
you
should
update
your
method
to
accept
this
argument.
HTTPHTTP
PSR-7コンパチビリティPSR-7 Compatibility
影響の可能性: 低いLikelihood Of Impact: Low
PSR-7レスポンスを生成するためのZend
Diactorosライブラリが非推奨となりました。このパッケージをPSR-7互換性のために使用している場合は、代わりにnyholm/psr7
Composerパッケージをインストールしてください。さらに、symfony/psr-http-message-bridge
Composerパッケージの^2.0
リリースもインストールしてください。The
Zend
Diactoros
library
for
generating
PSR-7
responses
has
been
deprecated.
If
you
are
using
this
package
for
PSR-7
compatibility,
please
install
the
nyholm/psr7
Composer
package
instead.
In
addition,
please
install
the
^2.0
release
of
the
symfony/psr-http-message-bridge
Composer
package.
メールMail
設定ファイルの変更Configuration File Changes
影響の可能性: 状況によるLikelihood Of Impact: Optional
複数のメイラーをサポートするために、Laravel7.xではデフォルトのmail
設定ファイルを変更し、mailers
の配列を含むようにしました。しかしながら、後方互換性のためにこのファイルのLaravel6.x形式もまだサポートしています。7.xへアップグレードするには変更は必要ありませんが、新しいmail
設定ファイルを確認し、変更を反映するほうを皆さん選ばれるでしょう。In
order
to
support
multiple
mailers,
the
default
mail
configuration
file
has
changed
in
Laravel
7.x
to
include
an
array
of
mailers
.
However,
in
order
to
preserve
backwards
compatibility,
the
Laravel
6.x
format
of
this
configuration
file
is
still
supported.
So,
no
changes
are
required
when
upgrading
to
Laravel
7.x;
however,
you
may
wish
to
examine
the
new
mail
configuration
file[https://github.com/laravel/laravel/blob/develop/config/mail.php]
structure
and
update
your
file
to
reflect
the
changes.
MarkdownメールテンプレートアップデートMarkdown Mail Template Updates
影響の可能性: 中程度Likelihood Of Impact: Medium
デフォルトMarkdownテンプレートが、よりプロフェッショナルな見かけの良いデザインに刷新されました。さらに、ドキュメントに記載されていないpromotion
Markdownメールコンポーネントが削除されました。The
default
Markdown
mail
templates
have
been
refreshed
with
a
more
professional
and
appealing
design.
In
addition,
the
undocumented
promotion
Markdown
mail
component
has
been
removed.
Markdownではインデントが特別な意味を持っているため、MarkdownメールではHTMLがインデントされていないことが期待されています。Laravelのデフォルトメールテンプレートを以前にリソース公開していた場合は、メールテンプレートを再リソース公開するか、自分でアンインデントしてください。Because indentation has special meaning within Markdown, Markdown mail templates expect unindented HTML. If you've previously published Laravel's default mail templates, you'll need to re-publish your mail templates or manually unindent them:
php artisan vendor:publish --tag=laravel-mail --force
Swift Mailer BindingsSwift Mailer Bindings
影響の可能性: 低いLikelihood Of Impact: Low
Laravel7.xでは、swift.mailer
とswift.transport
のコンテナ結合は提供していません。これらのオブジェクトは、mailer
の結合を経由してアクセスできます。Laravel
7.x
doesn't
provide
swift.mailer
and
swift.transport
container
bindings.
You
may
now
access
these
objects
through
the
mailer
binding:
$swiftMailer = app('mailer')->getSwiftMailer();
$swiftTransport = $swiftMailer->getTransport();
リソースResources
Illuminate\Http\Resources\Json\Resource
クラスThe
Illuminate\Http\Resources\Json\Resource
Class
影響の可能性: 低いLikelihood Of Impact: Low
非推奨だったIlluminate\Http\Resources\Json\Resource
クラスは削除されました。代わりにリソースはIlluminate\Http\Resources\Json\JsonResource
を拡張してください。The
deprecated
Illuminate\Http\Resources\Json\Resource
class
has
been
removed.
Your
resources
should
extend
the
Illuminate\Http\Resources\Json\JsonResource
class
instead.
ルートRouting
ルータのgetRoutes
メソッドThe
Router
getRoutes
Method
影響の可能性: 低いLikelihood Of Impact: Low
ルータのgetRoutes
メソッドはIlluminate\Routing\RouteCollection
のインスタンスの代わりに、Illuminate\Routing\RouteCollectionInterface
のインスタンスを返すようになりました。The
router's
getRoutes
method
now
returns
an
instance
of
Illuminate\Routing\RouteCollectionInterface
instead
of
Illuminate\Routing\RouteCollection
.
一意のルート名Unique Route Names
影響の可能性: 中程度Likelihood Of Impact: Medium
公式にはドキュメントに載せていませんが、以前のLaravelリリースでは異なった2つのルートを同じ名前で定義できていました。Laravel7ではこれはできなくなり、いつでもルートに一意の名前を指定する必要があります。重複する名前を持つルートはフレームワークの複数のエリアで、予期せぬ振る舞いを引き起こす可能性があります。Even though never officially documented, previous Laravel releases allow you to define two different routes with the same name. In Laravel 7 this is no longer possible and you should always provide unique names for your routes. Routes with duplicate names can cause unexpected behavior in multiple areas of the framework.
CORSサポートCORS Support
影響の可能性: 中程度Likelihood Of Impact: Medium
Cross-Origin
Resource
Sharing
(CORS)がデフォルトで統合されました。もしサードパーティ製ライブラリを使用していた場合は、新しいcors
設定ファイルを使用することを勧めます。Cross-Origin
Resource
Sharing
(CORS)
support
is
now
integrated
by
default.
If
you
are
using
any
third-party
CORS
libraries
you
are
now
advised
to
use
the
new
cors
configuration
file[https://github.com/laravel/laravel/blob/master/config/cors.php].
次に、アプリケーションの依存パッケージへ、Laravelの後ろで動作するCORSライブラリをインストールします。Next, install the underlying CORS library as a dependency of your application:
composer require fruitcake/laravel-cors
最後に、App\Http\Kernel
グローバルミドルウェアへ\Fruitcake\Cors\HandleCors::class
ミドルウェアを追加します。Finally,
add
the
\Fruitcake\Cors\HandleCors::class
middleware
to
your
App\Http\Kernel
global
middleware
list.
セッションSession
array
セッションドライバThe
array
Session
Driver
影響の可能性: 低いLikelihood Of Impact: Low
array
セッションドライバのデータは、現在のリクエスト中維持するようになりました。以前は、array
セッションに保存したデータは、現在のリクエスト中でさえ取得できませんでした。The
array
session
driver
data
is
now
persistent
for
the
current
request.
Previously,
data
stored
in
the
array
session
could
not
be
retrieved
even
during
the
current
request.
テストTesting
assertSee
アサーションThe
assertSee
Assertion
影響の可能性: 中程度Likelihood Of Impact: Medium
TestResponse
クラスのassertSee
、assertDontSee
、assertSeeText
、assertDontSeeText
、assertSeeInOrder
、assertSeeTextInOrder
アサーションは、自動的に値をエスケープするようになりました。これらのアサーションに渡す値を今まで自分でエスケープしていたのであれば、これからはそうしてはいけません。エスケープしない値でアサートする必要がある場合は、メソッドの第2引数にfalse
を指定してください。The
assertSee
,
assertDontSee
,
assertSeeText
,
assertDontSeeText
,
assertSeeInOrder
and
assertSeeTextInOrder
assertions
on
the
TestResponse
class
will
now
automatically
escape
values.
If
you
are
manually
escaping
any
values
passed
to
these
assertions
you
should
no
longer
do
so.
If
you
need
to
assert
unescaped
values,
you
may
pass
false
as
the
second
argument
to
the
method.
TestResponse
クラスThe
TestResponse
Class
影響の可能性: 低いLikelihood Of Impact: Low
Illuminate\Foundation\Testing\TestResponse
クラスはIlluminate\Testing\TestResponse
へリネームされました。もしこのクラスを拡張していた場合は、名前空間を確実に変更してください。The
Illuminate\Foundation\Testing\TestResponse
class
has
been
renamed
to
Illuminate\Testing\TestResponse
.
If
you're
extending
this
class,
make
sure
to
update
the
namespace.
The
Assert
ClassThe
Assert
Class
影響の可能性: 低いLikelihood Of Impact: Low
Illuminate\Foundation\Testing\Assert
クラスはIlluminate\Testing\Assert
へリネームされました。このクラスを使用していた場合は、名前空間部分を変更してください。The
Illuminate\Foundation\Testing\Assert
class
has
been
renamed
to
Illuminate\Testing\Assert
.
If
you're
using
this
class,
make
sure
to
update
the
namespace.
バリデーションValidation
different
ルールThe
different
Rule
影響の可能性: 中程度Likelihood Of Impact: Medium
different
ルールは、リクエストに指定したパラメータのうちの1つが足りないければ失敗するようになりました。The
different
rule
will
now
fail
if
one
of
the
specified
parameters
is
missing
from
the
request.
その他Miscellaneous
laravel/laravel
のGitHubリポジトリで、変更を確認することを推奨します。これらの変更は必須でありませんが、皆さんのアプリケーションではファイルの同期を保つほうが良いでしょう。変更のいくつかは、このアップグレードガイドで取り扱っていますが、設定ファイルやコメントなどの変更は取り扱っていません。変更は簡単に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.
You
can
easily
view
the
changes
with
the
GitHub
comparison
tool[https://github.com/laravel/laravel/compare/6.x...master]
and
choose
which
updates
are
important
to
you.