John Davidson

php - Laravel 7: How to edit the message in verification email

0 comments
Message:


I am trying to edit Laravel default email verification message.
I have tried publishing the notification and mail resources.


php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail

New folders called mail and notification were created in resource>views>vendor but I haven't been able to find the file which holds the codes for the message in either of the folders. I found a file that seems like the one in vendor>laravel>framework>src>Illuminate>Auth>Notification which is called VerifyEmail but I'm not sure if I'm suppose to change this file since I couldn't find any article online talking about this file.
My Laravel version is 7.15.0.


Any help would be appreciated as I have tried multiple methods with no success.


Thank you in advance.



My Answer:
To edit the message in the verification email in Laravel 7, you can create a new notification class that extends the default Laravel verification notification class. Here's how you can do it:

1. Create a new notification class by running the following command in your terminal:
bash
php artisan make:notification CustomVerifyEmail


2. This will create a new notification class in the `app/Notifications` directory. Open the `CustomVerifyEmail.php` file and modify the `toMail` method to customize the email message. Here's an example of how you can customize the message:
php
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Custom Email Verification')
->line('Please click the button below to verify your email address.')
->action('Verify Email', $this->verificationUrl($notifiable))
->line('If you did not create an account, no further action is required.');
}


3. Next, in your `User` model, make sure to implement the `MustVerifyEmail` interface and use the `CustomVerifyEmail` notification class. Your `User` model should look something like this:
php
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;

// ...

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


4. Finally, make sure to update your `verification.blade.php` file in the `resources/views/auth/emails` directory to reflect the changes in the email message.

With these steps, you should be able to customize the message in the verification email in Laravel 7. Let me know if you have any further questions.

Rate this post

5 of 5 based on 5158 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us