LoginSignup
0

More than 5 years have passed since last update.

第2回 Laravelプルリクで学ぶ英語講座

Posted at

今回のプルリクはこちらです。

[5.7] Allow Gates / Policies To Accept "Guests"

This PR allows gates and policies to allow "guest users" (null) to be passed to them instead of automatically returning false. They can allow this by marking their user type-hint as optional or providing a null default value for the incoming user:

$gate->define('foo', function (?User $user) {
    return true;
});

簡単に概要を説明すると、GatesとPolicyにゲストユーザー(null)をパラメタとして渡すことができるように変更したというものです。
*GatesとPolicyは、モデル保存時などにユーザーの認証を行うクラスです。
ドキュメント

それではまずはタイトルから見て見ましょう。

タイトル
英: Allow Gates / Policies To Accept "Guests"
日: GatesとPolicyがGuestを受け付けるようにする

はい。これは特に説明は不要ですね。
allowもacceptもよく使われるので覚えておきましょう

allow: 許可する、許す、できるようにする
accept: 認める、受け入れる

allowはここでは「できるようにする」という意味だと理解してください。

次は内容を見ていきます。

This PR allows gates and policies to allow "guest users" (null) to be passed to them instead of automatically returning false. They can allow this by marking their user type-hint as optional or providing a null default value for the incoming user:

まずは読みやすいように自分で文章を分割してみましょう。
分割してみたら次を読み進めてください。

分割の仕方に厳密な方法はありませんが、私は以下のように分割しました。
分割の仕方については前回も少し触れているので読んでいない方は参照ください。

This PR allows gates and policies
to allow "guest users" (null) to be passed to them
instead of automatically returning false.

They can allow this
by marking their user type-hint
as optional or providing a null default value
for the incoming user:

$gate->define('foo', function (?User $user) {
    return true;
});

それではこれを一行ずつ訳していきます。

英:This PR allows gates and policies
日:このプルリクエストはゲートとポリシーができるようにする

この時点では何をできるようにするのかわかりませんが、次に進みます。

英:to allow "guest users" (null) to be passed to them
日: ゲストユーザー(null)をそれらに渡すことを可能にする

them(それら)はゲートとポリシーのことです。

英:instead of automatically returning false.
日: 自動的にfalseを返す代わりに

ここまでをまとめると以下のようになります。

英: This PR allows gates and policies to allow "guest users" (null) to be passed to them instead of automatically returning false.
日: このプルリクエストは、ゲートとポリシーに自動的にfalseを返す代わりにゲストユーザー(null)を渡せるようにする。

ちょっと長くなったので、今日はここまでにします。

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
0