Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how-to-customize-the-email-verification-email-from-laravel-8

Step: 1

Create a new notification UserVerifyNotification class. It should extend the VerifyEmail class from the library IlluminateAuthNotificationsVerifyEmail;

Code :
use IlluminateAuthNotificationsVerifyEmail;
    ...
    class UserVerifyNotification extends VerifyEmail implements ShouldQueue
    {
        use Queueable;
        public $user;            //you'll need this to address the user
    
        /**
         * Create a new notification instance.
         *
         * @return void
         */
        public function __construct($user='')
        {
            $this->user =  $user ?: Auth::user();         //if user is not supplied, get from session
        }
    
        /**
         * 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 IlluminateNotificationsMessagesMailMessage
         */
        public function toMail($notifiable)
        {
            $actionUrl  = $this->verificationUrl($notifiable);     //verificationUrl required for the verification link
            $actionText  = 'Click here to verify your email';
            return (new MailMessage)->subject('Verify your account')->view(
                'emails.user-verify',
                [
                    'user'=> $this->user,
                    'actionText' => $actionText,
                    'actionUrl' => $actionUrl,
                ]);
        }
    
        /**
         * Get the array representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function toArray($notifiable)
        {
            return [
                //
            ];
        }
        
    }
Step:2

Create the blade view for the email (user-verify.blade.php) inside resourcesviewsemails
Step:3

Add the following method inside the User model
class User extends Authenticatable implements MustVerifyEmail
   {
    use HasFactory, Notifiable;

    ...
    ...
    ...

    public function sendEmailVerificationNotification()
    {
        $this->notify(new AppNotificationsUserVerifyNotification($this->getAttributes()));  //pass the currently logged in user to the notification class
    }

}

Comment

PREVIOUS NEXT
Code Example
Php :: acho in php 
Php :: how to change phpto size in its properties ubuntu 
Php :: PHP catch eval output 
Php :: .htaccess Preventing access to your PHP includes files 
Php :: php limit results by 30 days 
Php :: codeigniter AES _ENCRYPT or AES_DECRYPT in where 
Php :: laravel has many deep 
Php :: wordpress remove current post in sidebar php 
Php :: vault deployment in production 
Php :: laravel collection makeVisible 
Php :: most complicated task ina array in php 
Php :: Convert Shamsi Jalali Persian Date TimeStamp 
Php :: php run python script with arguments json 
Php :: command ui is not found 
Php :: load player avatar url 
Php :: laravel {{}} not being rendered 
Php :: laravel validation error messages are not showing on register oage 
Php :: Date and time Asia karachi php 
Php :: php header deny 
Php :: javascript date to php date site:stackoverflow.com 
Php :: symfony server:start not working 
Php :: MySQL eqSql Connection 
Php :: php html entity for url 
Php :: How to prevent repeating the same option value of a selection in a php loop 
Php :: redaxo urlGenerator, urlGenerator::getId(), Class "UrlGenerator" not found 
Php :: php getUserStateFromRequest 
Php :: phpmailer valid cert 
Php :: if($a $b){ echo "A B"; }else if($a < $b){ echo "A < B"; }else if($a != ""){ if($a == $b){ echo "A = B"; } } 
Php :: wp table with hostname setup 
Php :: lista 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =