Readouble

Laravel 5.7 メール確認

イントロダクションIntroduction

多くのWebアプリケーションはアプリケーション利用開始前に、ユーザーのメールアドレスを確認する必要があります。アプリケーションごとに再実装しなくても済むように、Laravelはメールを送信し、メールの確認リクエストを検証する便利なメソッドを用意しています。Many web applications require users to verify their email addresses before using the application. Rather than forcing you to re-implement this on each application, Laravel provides convenient methods for sending and verifying email verification requests.

モデルの準備Model Preparation

利用を開始するには、App\UserモデルがIlluminate\Contracts\Auth\MustVerifyEmail契約を実装していることを確認してください。To get started, verify that your App\User model implements the Illuminate\Contracts\Auth\MustVerifyEmail contract:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    // ...
}

データベースの検討Database Considerations

メール確認カラムThe Email Verification Column

次に、メールアドレスを確認した日時を保存するための、email_verified_atカラムをusersテーブルに含める必要があります。Laravelフレームワークにデフォルトで含まれている、usersテーブルマイグレーションには、あらかじめこのカラムが準備されています。ですから、必要なのはデータベースマイグレーションを実行することだけです。Next, your user table must contain an email_verified_at column to store the date and time that the email address was verified. By default, the users table migration included with the Laravel framework already includes this column. So, all you need to do is run your database migrations:

php artisan migrate

ルートRouting

確認リンクを送信し、メールを確認するために必要なロジックを含む、Auth\VerificationControllerクラスをLaravelは用意しています。このコントローラに必要なルートを登録するには、Auth::routesメソッドに、verifyオプションを渡してください。Laravel includes the Auth\VerificationController class that contains the necessary logic to send verification links and verify emails. To register the necessary routes for this controller, pass the verify option to the Auth::routes method:

Auth::routes(['verify' => true]);

保護下のルートProtecting Routes

Routeミドルウェアを指定したルートに対しメールアドレス確認済みのユーザーのみアクセスを許すために使用します。Illuminate\Auth\Middleware\EnsureEmailIsVerifiedで定義しているverifiedミドルウェアをLaravelは用意しています。このミドルウェアは、アプリケーションのHTTPカーネルで登録済みですので、ルート定義にこのミドルウェアを指定するだけです。Route middleware[/docs/{{version}}/middleware] can be used to only allow verified users to access a given route. Laravel ships with a verified middleware, which is defined at Illuminate\Auth\Middleware\EnsureEmailIsVerified. Since this middleware is already registered in your application's HTTP kernel, all you need to do is attach the middleware to a route definition:

Route::get('profile', function () {
    // Only verified users may enter...
})->middleware('verified');

ビューViews

make:authコマンドを実行すると、Laravelはメール確認に必要なビューを全て生成します。ビューはresources/views/auth/verify.blade.phpとして生成されます。アプリケーションの必要に応じ、自由にこのビューをカスタマイズしてください。Laravel will generate all of the necessary email verification views when the make:auth command is executed. This view is placed in resources/views/auth/verify.blade.php. You are free to customize this view as needed for your application.

メール確認後After Verifying Emails

メールアドレスを確認後、ユーザーを自動的に/homeヘリダイレクトします。VerificationControllerredirectToメソッドかプロパティにより、確認後のリダイレクト先をカスタマイズできます。After an email address is verified, the user will automatically be redirected to /home. You can customize the post verification redirect location by defining a redirectTo method or property on the VerificationController:

protected $redirectTo = '/dashboard';

イベントEvents

メールの確認過程で、Laravelはイベントをディスパッチします。EventServiceProviderの中で、これらのイベントにリスナを指定できます。Laravel dispatches events[/docs/{{version}}/events] during the email verification process. You may attach listeners to these events in your EventServiceProvider:

/**
 * アプリケーションにマップするイベントリスナ
 *
 * @var array
 */
protected $listen = [
    'Illuminate\Auth\Events\Verified' => [
        'App\Listeners\LogVerifiedUser',
    ],
];

章選択

設定

明暗テーマ
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!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

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

コードフォント

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

保存内容リセット

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

ヘッダー項目移動

キーボード操作