doumei1955 2019-03-02 06:21
浏览 145
已采纳

Laravel 5.7 Multilogin SendEmailVerificationNotification错误

I'm new to Laravel. I just created a custom login with laravel 5.7. When I tried to reset password I'm getting this error:

"Declaration of App\Employee::sendEmailVerificationNotification($token) should be compatible with Illuminate\Foundation\Auth\User::sendEmailVerificationNotification()"

Does anyone know how to resolve this error?

  • 写回答

2条回答 默认 最新

  • dongxianrang9269 2019-03-02 08:51
    关注

    You may do something like this

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

    if you want to call it like Employee::sendEmailVerificationNotification() and if you want to verify the token you should extend the VerifyEmail notification something like

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

    Then in Employee model

    public function sendEmailVerificationNotification($token)
        {
            $this->notify(new VerifyEmailNotification($token)); // your custom notification
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办