Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Sending Invitation Email and Accept Route

Premium
3:10

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 Invitation Model as a parameter. Then, we will be able to add the tenant's name to the email.

app/Http/Notifications/SendInvitationNotification.php:

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...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

P
prosp3ro ✓ Link copied!

there seems to be a typo - SendInvitationNotification class will accept the Invitation Model as a parameter, not Notification model

PK
Povilas Korop ✓ Link copied!

Well noticed, fixed now! One of the advantage of having text lessons and not video: quick to fix.