Video Version of the Lesson
[Only for premium members]
[Only for premium members]
[Only for premium members]
Let's finish the invitation system by accepting the invitation.
If I'm logged in to another tenant at the moment, I need to:
app/Http/Controllers/UserController.php:
class UserController extends Controller{ // ... public function acceptInvitation(string $token) { $invitation = Invitation::where('token', $token) ->whereNull('accepted_at') ->firstOrFail(); if (auth()->check()) { $invitation->update(['accepted_at' => now()]); auth()->user()->tenants()->attach($invitation->tenant_id); auth()->user()->update(['current_tenant_id' => $invitation->tenant_id]); $tenantDomain = str_replace('://', '://' . $invitation->tenant->subdomain . '.', config('app.url')); return redirect($tenantDomain . route('dashboard', absolute: false)); } else { // redirect to register } }}
Now, if I register with a new user, this user has only its own tenant.
From another user, I send email invitations to the newly registered user.
As you can see, when the invitation is accepted, the user should be redirected to the bbb
subdomain tenant and should have two tenants.
We can see that after accepting the invitation, the user is redirected to...