Create InvitedToSpace mail
MODIFY
app/Http/Controllers/SpaceController.php
app/Http/Controllers/SpaceController.php
@@ -5,11 +5,13 @@ namespace App\Http\Controllers;
use App\Actions\CreateSpaceInviteAction;
use App\Exceptions\SpaceInviteAlreadyExistsException;
use App\Exceptions\SpaceInviteInviteeAlreadyPresentException;
+use App\Mail\InvitedToSpace;
use App\Models\Space;
use App\Models\SpaceInvite;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Mail;
class SpaceController extends Controller
{
@@ -66,7 +68,7 @@ class SpaceController extends Controller
$inviteeUser = User::where('email', $request->email)->first();
try {
- (new CreateSpaceInviteAction())->execute(
+ $invite = (new CreateSpaceInviteAction())->execute(
$space->id,
$inviteeUser->id,
$authenticatedUser->id,
@@ -82,7 +84,7 @@ class SpaceController extends Controller
->with('inviteStatus', 'exists');
}
- // TODO SEND MAIL
+ Mail::to($inviteeUser->email)->send(new InvitedToSpace($invite));
return redirect()
->route('spaces.edit', ['space' => $space->id])

ADD
app/Mail/InvitedToSpace.php
+<?php
+
+namespace App\Mail;
+
+use App\Models\SpaceInvite;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Queue\SerializesModels;
+
+class InvitedToSpace extends Mailable
+{
+ use Queueable;
+ use SerializesModels;
+
+ protected $invite;
+
+ public function __construct(SpaceInvite $invite)
+ {
+ $this->invite = $invite;
+ }
+
+ public function build()
+ {
+ return $this
+ ->view('emails.invited_to_space')
+ ->text('emails.invited_to_space_plain')
+ ->with(['invite' => $this->invite]);
+ }
+}

ADD
resources/views/emails/invited_to_space.blade.php
+@extends('emails.template')
+
+@section('content')
+ {{ $invite->inviter->name }} has invited you to "{{ $invite->space->name }}".
+
+ <a href="{{ route('space_invites.show', ['space' => $invite->space->id, 'invite' => $invite->id]) }}">Check out your invite</a>
+@endsection

ADD
resources/views/emails/invited_to_space_plain.blade.php
+{{ $invite->inviter->name }} has invited you to "{{ $invite->space->name }}"
+
+Use the link below to check out your invite.
+
+{{ route('space_invites.show', ['space' => $invite->space->id, 'invite' => $invite->id]) }}

Create InvitedToSpace mail