Customize Laravel Verification Email

xtremeCODE :

please I am trying to customize Laravel Verification Email

In my user model, I have this

  public function sendEmailVerificationNotification()
    {
        $this->notify(new MyNotification);
    }

I then ran

php artisan make:notification MyNotification

In it, I have this

<?php

namespace App\Notifications;
use Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;


class MyNotification extends Notification
{
    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)
    {

        return (new MailMessage)
        ->subject('Verify Email Address')
        //I am trying output Hello User Name
        ->greeting('Hello!' {Auth::user()->name} )
        ->line('The introduction to the notification.')
        ->line('Please click the button below to verify your email address.')
        ->action(Lang::get('Verify Email Address'), $verificationUrl)
        ->line('If you did not create an account, no further action is required.')
        ->line('Thank you for using our application!');
    }

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

This

greeting('Hello!' {Auth::user()->name}

returned an error

Illegal string offset 'John Doe'

This

action(Lang::get('Verify Email Address'), $verificationUrl)

returned error

Undefined variable: verificationUrl

I then added this,

   $verificationUrl = $this->verificationUrl($notifiable);

It returned new error

Call to undefined method App\Notifications\MyNotification::verificationUrl()

I don't really know what to do at this point.

Anton Németh :
  1. Greeting fix:
->greeting('Hello! ' . Auth::user()->name)
  1. For that verificationUrl I think you have to extend \Illuminate\Auth\Notifications\VerifyEmail instead of Notification

see this: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Auth/Notifications/VerifyEmail.php

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=375517&siteId=1