A
A
Alex2021-07-11 10:49:16
Laravel
Alex, 2021-07-11 10:49:16

How to replace Laravel 8 Breeze emails?

When using Breeze, letters with mail confirmation, password recovery, etc., come with standard Laravel templates. How to make your own blade templates for all notifications and send them to users already?

p/s/ Completely your own design and your own text for each type of notification

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
netrox, 2021-07-11
@netrox

Edit the appropriate files in the resources/views/auth. For example: verify-email.blade.php.

A
Alex, 2021-07-12
@alexjet73

The solution has been found. I'll leave it here if anyone needs it:
1. Replacing letter templates (design)
, run two commands in the terminal

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

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

We get two folders mail and notifications in \resources\views\vendor\.
In the mail in the html folder, we change the header, footer and everything you need.
2. Change the text of notifications.
To do this, we create two custom notifiers using the php artisan make:notification command.
For example:
php artisan make:notification MyVerifyMail
php artisan make:notification MyResetPass

The app/Notifications folder appears.
Now we take the standard notifiers from the core, they are located in the \vendor\laravel\framework\src\Illuminate\Auth\Notifications folder.
We copy the entire class body from them and paste it, replacing the class body in the custom notifier (do not forget to also import all the necessary namespaces with use).
Now we edit the text in the buildMailMessage method in both notifiers to the one we need. You can also specify greeting in addition to subject in order to personalize the greeting text in letters.
return (new MailMessage)
      ->greeting('Здравствуйте!')

When everything is ready, we add two methods to app\Models\User.php, overriding the standard ones:
public function sendEmailVerificationNotification(){
    $this->notify(new MyVerifyMail());
  }
  public function sendPasswordResetNotification($token)
  {
    $this->notify(new MyResetPass($token));
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question