Laravel使用默认的电子邮件确认客人

问题描述 投票:0回答:2

我有一个关于我的确认电子邮件,来宾代码的问题。我有一个评论系统。当客户阅读后,他可以写一个评论。当他添加评论,客人只需确认电子邮件(评论形式,我有一个电子邮件字段)。我该怎么做正确的电子邮件确认?如何在Laravel,当用户注册。

现在我有表“客人”和模型客户,与列:nameemailemail_tokenemail_verified_at(如何在用户表)。

在模型客人我有功能:

public function sendEmailNotification($token)
{
    $this->notify((new ReviewEmailNotification($token)));
}

当创建评论,我称之为观察功能created和发送电子邮件:

public function created(Review $review)
{
    Auth::guest() ? $review->sendEmailNotification($review->email_token) : '';
}

我的通知:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Lang;

class ReviewEmailNotification extends Notification
{
    use Queueable;
public $token;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct($token)
{
    $this->token = $token;
}

/**
 * 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)
{
    return (new MailMessage)
        ->subject(Lang::getFromJson('Verify comment'))
        ->line(Lang::getFromJson('Please confirm your Email:'))
        ->action(Lang::getFromJson('Confirm E-Mail'), url(config('app.url') . route('revemail', $this->token)))
        ->line(Lang::getFromJson('...'));
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
    ];
}
}

我的确认电子邮件功能:

public function activateEmail($token = null)
{
    $guest = Guest::where('email_token', $token)->first();

    if ($review) {
        $guest->email_verified_at = now();
        $guest->save();
    }

    return redirect()->route('home');
}

当电子邮件验证我创建的客人表记录。

该解决方案的工作。但如何我可以从email_token走吗?在用户表我只有无柱令牌email_verified_at。我希望做令牌到期日期,如何laravel。我可以供客人使用默认laravel电子邮件确认?

php laravel
2个回答
0
投票

目前简单的修改sendEmailNotification这是接受$令牌改变它的电子邮件和你的功能,你正在使用令牌改变它的电子邮件是这样的:

打开此功能ReviewEmailNotification

modify like this Review::where('email',$email)

希望更多的帮助,然后张贴ReviewEmailNotification的完整代码


0
投票

终于我明白你的查询,你必须改变的代码....不要使用用户表,因为每一个岗位/文章将发表新评论/审查,以便客人表将是良好的,并添加POST_ID,USER_ID电子邮件确认,因此新的功能是这样的

public function created(Review $review)
{
    Auth::guest() ? $review->sendEmailNotification($review-> post_id,$review->user_id,) : '';
}



public function activateEmail($token = null)
{
    $guest = Guest::where('post_id', $post_id)->where('user_id', $user_id)->first();

    if ($review) {
        $guest->email_verified_at = now();
        $guest->save();
    }

    return redirect()->route('home');
}



public function sendEmailNotification($user_id,$post_id)
{
    $this->notify((new ReviewEmailNotification($post_id,$user_id )));
}
© www.soinside.com 2019 - 2024. All rights reserved.