invite team member
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Teams;
|
||||
|
||||
use App\Models\TeamInvite;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
readonly class AcceptTeamInvite
|
||||
{
|
||||
public function __invoke(TeamInvite $invite): void
|
||||
{
|
||||
abort_unless(auth()->user()->email === $invite->invited_email, 403);
|
||||
|
||||
$team = $invite->team;
|
||||
$newUser = User::whereEmail($invite->invited_email)->firstOrFail();
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($team, $newUser, $invite) {
|
||||
$team->members()->attach($newUser);
|
||||
$invite->delete();
|
||||
});
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user