` protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
//創立用戶資料
protected function create(array $data)
{
//變量
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'avatar' => '/images/avatars/default.png', //頭像目錄
'confirmation_token'=> str_random(40), //使用laravel提供的function 函數 默認40字串
'password' => bcrypt($data['password']),
]);
$this->sendVerifyEmailTo($user);
return $user;
}
//發送用戶信件
private function sendVerifyEmailTo($user)
{
$data = [
'url' => route('email.verify',['token'=>$user->confirmation_token]),
'name' => $user->name
];
$template = new SendCloudTemplate('zhihu', $data); //選擇模板
Mail::raw($template, function ($message) use ($user) {
$message->from('[email protected]', 'yellow'); //發送信件者
$message->to($user->email); //接收信件者
});
}`