invite team member
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\TeamInvite;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class InviteToTeam extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(TeamInvite $invite): MailMessage
|
||||
{
|
||||
$user = User::whereEmail($invite->invited_email)->first();
|
||||
|
||||
return (new MailMessage)
|
||||
->subject('Team Invitation')
|
||||
->greeting(
|
||||
$user !== null
|
||||
? sprintf('Hello %s,', $user->name)
|
||||
: 'Hello',
|
||||
)
|
||||
->line(sprintf(
|
||||
'%s invited you to the %s team.',
|
||||
$invite->invitedBy->name,
|
||||
$invite->team->name,
|
||||
))
|
||||
->linesIf($user === null, [
|
||||
'It seems like you don\'t have an account yet.',
|
||||
'Create one now for free to join the team.',
|
||||
])
|
||||
->action($user === null
|
||||
? 'Register and join this team'
|
||||
: 'Join this team',
|
||||
route($user === null
|
||||
? 'register'
|
||||
: 'teams.invite.create',
|
||||
['inviteToken' => $invite->plainInviteToken()]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user