-
Create an account in https://mailtrap.io/
-
In the Home click in the Setup Inbox Button
- Select the Laravel 7+ Integration
- Copy the connection values
- in the
env
file, replace the email connection information with the mailtrap connection values
- Run the following command to create a new Notification
php artisan make:notification SendRegistrationEmail
- Add a protected property to receive the
$user
as parameter in the constructor
public $user;
public function __construct($user)
{
$this->user = $user;
}
- Replace the
toMail()
function with the following code
public function toMail($notifiable)
{
return (new MailMessage)
->line('Dear '. $this->user->name . '. This is a notification to let you know that you were registered to our site.')
->action('You were succesfully registered' ., url('/'))
->line('Thank you for using our application!');
}
- Add
database
in thevia()
function return array
return ['mail', 'database'];
- In the
UserController.php
add the following line in thestore()
function
$user->notify(new SendRegistrationEmail($user));
- Run the following command to create a database migration to create the notifications table
php artisan notification:table
- Run the following command to run the migration and seed the database
php artisan migrate:refresh --seed