这个好像有个问题?

点连接报错
file

file

token 是空的

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
leo
最佳答案

"amp;token" => "f8O3aZ97ScYgVCRi"

很明显 key 不对啊,应该是 token 而不是 amp;token,通知类的代码贴出来看看,以及点击链接之后浏览器的 URL 是啥

5年前 评论
讨论数量: 12
Jourdon

file

5年前 评论
leo

在第一行 dd($request->all()) 看看输出啥

5年前 评论

这个链接的token和数据库里的不一致

5年前 评论

dd($request->all());
array:2 [▼
"email" => "dancheng9999@163.com"
"amp;token" => "f8O3aZ97ScYgVCRi"
]
有值但是为啥会报这行呢

file

5年前 评论
Jourdon

@dancheng token是存在缓存里的,不是在数据库里,提醒类下的toMail里面生成的token,在EmailVerificationController 控制器里的verify获取的token,自己去看代码,哪里写错了。

5年前 评论

EmailVerificationController 里面dd($request->all());
array:2 [▼
"email" => "dancheng9999@163.com"
"amp;token" => "f8O3aZ97ScYgVCRi"
]
说明有值
但是
if (!$email || !$token) {
throw new Exception('验证链接不正确');
}
这里的时候报错 验证链接不正确

5年前 评论

我改成这样好了
if (is_null($email) && is_null($token)) {
throw new Exception('验证链接不正确');
}

5年前 评论
leo

"amp;token" => "f8O3aZ97ScYgVCRi"

很明显 key 不对啊,应该是 token 而不是 amp;token,通知类的代码贴出来看看,以及点击链接之后浏览器的 URL 是啥

5年前 评论

我看了 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" 这个怎么改

5年前 评论
leo

@dancheng 通知类的代码贴出来看看,以及点击链接之后浏览器的 URL 是啥

5年前 评论

<?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 [
        //
    ];
}

}

点了连接地址栏显示这个
file

5年前 评论
yunshu2009

我也遇到这个问题,将通知邮件的模板发布出来,去掉模板里 url 的转义(将{{ }}改为{!! !!}} 就可以了。

file

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!