Next, we need to send the invitation via email.
Laravel Notification Class
Let's create an Laravel Notification class for invitations.
php artisan make:notification SendInvitationNotification
The SendInvitationNotification
class will accept the Notification
Model as a parameter. Then, we will be able to add the tenant's name to the email.
app/Http/Notifications/:
use App\Models\Invitation; class SendInvitationNotification extends Notification{ use Queueable; public function __construct(private readonly Invitation $invitation) { // } public function via(object $notifiable): array { return ['mail']; } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line("You are invited to the team {$this->invitation->tenant->name}") ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } // ...}
To call $this->invitation->tenant
, we need to add one more thing: we haven't yet added the tenant...