-> 当用户创建帐户时,会向他发送一封验证邮件。这是我的目标。
->我正在使用 Laravel,我是新手。
->我正确设置了所需的 STMP 详细信息,如密码、用户名、端口、加密
->我希望我是清楚的。
->在 email.php 中,发件人是:“发件人”=> [“发件人”=> [“地址”=> null,“名称”=> null],
所以我的代码是:
验证控制器.php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class VerifyController extends Controller
{
/**
* verify the user with a given token
*
*
*/
public function verify($token)
User::where('token', $token)->firstOrFail();
$this->update(['token' => null]); //verify the user
return redirect('/profile');
$this->route('home')
->with('success', 'Account verifed');
}
}
用户.php
<?php
namespace App;
use App\User;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Notifications\VerifyEmail;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password', 'token'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function orders(){
return $this->hasMany('App\Order');
}
/**
* Returns true if user is verified
* @return bool
*
*/
public function verified()
{
return $this->token === null;
}
/**
* Send the user a verification user
* @return void
*
*
*
* */
public function sendVerificationEmail()
{
$this->notify(new VerifyEmail($this));
}
}
波斯汪