Team Invite
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Team;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class TeamInviteController extends Controller
|
||||
{
|
||||
|
||||
public function store(Request $request, Team $team)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'email' => 'required|email|max:255',
|
||||
]);
|
||||
|
||||
abort_unless(auth()->user()->can('manage', $team), 403);
|
||||
|
||||
$team->invites()->create([
|
||||
'invited_email' => Arr::get($validated, 'email'),
|
||||
'invited_by_user_id' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
Inertia::flash('success', 'User invited to your team.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Team $team): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'email' => 'required|email|max:255',
|
||||
]);
|
||||
|
||||
$teamInvite = $team->invites()->whereInvitedEmail(Arr::get($validated, 'email'))->firstOrFail();
|
||||
|
||||
try {
|
||||
$teamInvite->delete();
|
||||
} catch (\Exception $exception) {
|
||||
report($exception);
|
||||
Inertia::flash('error', 'could not delete user invite.');
|
||||
|
||||
return to_route('teams.show', $team);
|
||||
}
|
||||
|
||||
Inertia::flash('success', 'successfully deleted user invite.');
|
||||
|
||||
return to_route('teams.show', $team);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user