Laravel 5.7 Multilogin SendEmailVerificationNotification错误

时间:2019-03-02 06:21:14

标签: php laravel laravel-5.7 laravel-notification

我是Laravel的新手。我刚刚使用laravel 5.7创建了一个自定义登录名。当我尝试重设密码时,出现此错误:

  

“的声明   App \ Employee :: sendEmailVerificationNotification($ token)应该是   与...兼容   Illuminate \ Foundation \ Auth \ User :: sendEmailVerificationNotification()“

有人知道如何解决此错误吗?

2 个答案:

答案 0 :(得分:0)

如果要覆盖它,则必须遵循相同的方法签名-

您要重写此方法-

Illuminate\Foundation\Auth\User::sendEmailVerificationNotification()

对此-

App\Employee::sendEmailVerificationNotification($token)

如果您注意到差异,则您已在方法中传递了$ token,而原始方法定义不支持该标记。

如果您需要与原始方法不同的签名,请创建其他方法。

答案 1 :(得分:0)

您可能会做类似的事情

class Employee extends Model implements MustVerifyEmail {
    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }
}

如果您想像Employee::sendEmailVerificationNotification()那样称呼它,并且如果您想验证令牌,则应该扩展VerifyEmail通知,例如

<?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\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;

use Illuminate\Auth\Notifications\VerifyEmail;

class VerifyEmailNotification extends VerifyEmail
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($token)
    {
        //verify 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)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable);
        }

        return (new MailMessage)
            ->subject(Lang::getFromJson('Verify Email Address'))
            ->line(Lang::getFromJson('Please click the button below to verify your email address'))
            ->action(
                Lang::getFromJson('Verify Email Address'),
                $this->verificationUrl($notifiable)
            )
            ->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
    }


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

然后在员工模型中

public function sendEmailVerificationNotification($token)
    {
        $this->notify(new VerifyEmailNotification($token)); // your custom notification
    }