0

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

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

有谁知道如何解决这个错误?

4

2 回答 2

0

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

您正在覆盖此方法-

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

对此——

App\Employee::sendEmailVerificationNotification($token)

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

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

于 2019-03-02T06:29:55.627 回答
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 [
            //
        ];
    }
}

然后在 Employee 模型中

public function sendEmailVerificationNotification($token)
    {
        $this->notify(new VerifyEmailNotification($token)); // your custom notification
    }
于 2019-03-02T08:51:56.147 回答