dd($request->all());
array:2 [▼
"email" => "dancheng9999@163.com"
"amp;token" => "f8O3aZ97ScYgVCRi"
]
有值但是为啥会报这行呢
@dancheng token是存在缓存里的,不是在数据库里,提醒类下的toMail
里面生成的token,在EmailVerificationController
控制器里的verify
获取的token,自己去看代码,哪里写错了。
EmailVerificationController 里面dd($request->all());
array:2 [▼
"email" => "dancheng9999@163.com"
"amp;token" => "f8O3aZ97ScYgVCRi"
]
说明有值
但是
if (!$email || !$token) {
throw new Exception('验证链接不正确');
}
这里的时候报错 验证链接不正确
"amp;token" => "f8O3aZ97ScYgVCRi"
很明显 key
不对啊,应该是 token
而不是 amp;token
,通知类的代码贴出来看看,以及点击链接之后浏览器的 URL 是啥
我看了 mailhog里的链接
If you’re having trouble clicking the "验证" button, copy and paste the URL below into your web browser: http://192.168.10.10/email_verification/ve...
里的&token 在控制器里&解释成 &加上amp; 所以有控制器得到 "amp;token" => "60isIvXQiSalacZF" 这个怎么改
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Str;
use Cache;
class EmailVerificationNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
// 使用 Laravel 内置的 Str 类生成随机字符串的函数,参数就是要生成的字符串长度
$token = Str::random(16);
// 往缓存中写入这个随机字符串,有效时间为 30 分钟。
Cache::set('email_verification_'.$notifiable->email, $token, 30);
$url = route('email_verification.verify', ['email' => $notifiable->email, 'token' => $token]);
return (new MailMessage)
->greeting($notifiable->name.'您好:')
->subject('注册成功,请验证您的邮箱')
->line('请点击下方链接验证您的邮箱')
->action('验证', $url);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
点了连接地址栏显示这个
推荐文章: