Featured image of post Day 9. Authentication-2 信箱驗證

Day 9. Authentication-2 信箱驗證

資源

Laravel7 30天: 目錄
專案連結: github - laravel7 之 30 天分享

前言

專案連結: github - laravel7 之 30 天分享

上一篇: Day 8. Authentication-1 登入註冊
今天來跟大家 信箱驗證

主要

信箱驗證其實也滿簡單的就是依照官方設定即可
一樣附上文件給大家 here!

設定 smtp

開啟 .env 設定,可以使用自己的 gmail 信箱寄信
可以參考別人分享的教學文

1
2
3
4
5
6
7
8
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=xxx@gmail.com
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=xxx@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

設定 User Model

開啟檔案 App\Models\User.php 加上 implements MustVerifyEmail

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
namespace App\Models;
 
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
 
class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;
 
    // ...
}

調整路由

開啟 routes/web.php 在 調整
Auth::routes();
Auth::routes([‘verify’ => true]);

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

DEMO

可以試著註冊看看,
就會收到驗證信了

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy