All jobs

Add Team Invitations to a Filament Panel

Yes. An agent adds an invitation model, a Members page with an invite action, a signed accept route, real tenant membership checks, Pest tests, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how tenancy is wired before adding anything to it. In an app like filamentphp/demo, app/Providers/Filament/AppPanelProvider.php registers a second panel at /app with registration(), passwordReset(), emailVerification(), tenant(Team::class) and tenantRegistration(RegisterTeam::class), discovering resources, pages and widgets under app/Filament/App; only two pages exist there, RegisterTeam, whose form has one name field, and Settings. app/Models/Team.php implements HasCurrentTenantLabel and has a users() belongs-to-many, and app/Models/User.php implements HasTenants with getTenants returning Team::all() and canAccessTenant returning true, so every user sees every team. The teams and team_user migrations give a team a name and a unique team_id, user_id pair, and the pivot migration seeds every existing user into every team. composer.json runs on PHP 8.4 with Filament 5, Laravel 12, Pest 3 in parallel, Larastan and Pint, and tests/Pest.php applies RefreshDatabase and signs in a factory user for everything under tests/Filament. phpunit.xml sets the array mailer and the sync queue, .env.example points mail at a local SMTP catcher, and database/factories has a UserFactory but no TeamFactory. There is no way to join a team other than being seeded into it.

The agent adds the invitation as its own record. A migration creates team_invitations with team_id and invited_by foreign keys, email, a token column holding the SHA-256 of a random string, expires_at, a nullable accepted_at, timestamps and a unique index on team_id and email. app/Models/TeamInvitation.php carries the relations, an isExpired() helper and a scope for pending invitations, with a TeamInvitationFactory and a TeamFactory beside it. app/Mail/TeamInvitationMail.php is a markdown mailable whose button links to a signed route carrying the plain token, valid for the invitation's lifetime. The accept route in routes/web.php sits behind the auth and signed middleware: a guest is sent to the App panel's login and returned by intended, a signed-in user whose email does not match the invitation sees a plain refusal, and a match attaches the user through syncWithoutDetaching, stamps accepted_at and redirects to the panel URL for that team.

The visible part is app/Filament/App/Pages/Members.php, a page in the App panel with a table of the current tenant's users from Filament::getTenant(), a header action Invite member whose form has one validated email field and whose handler creates the invitation and sends the mail, and a second table of pending invitations with Resend and Revoke actions. With real memberships in place the agent also fixes the two methods that made tenancy nominal: getTenants returns $this->teams and canAccessTenant checks $this->teams->contains($tenant). Because of that, RegisterTeam gains a handleRegistration override that attaches the creating user to the new team, since the default only creates the record and the creator would otherwise lose sight of the team they just made. The pivot migration already seeded every user into every team, so no existing account loses access when the check becomes real.

Tests follow the shape of tests/Filament/Resources/Shop/Orders/Pages/ListOrdersTest.php. tests/Filament/App/Pages/MembersTest.php sets the tenant with Filament::setTenant, renders the page with Livewire::test, calls the invite action with TestAction and asserts a team_invitations row and one queued mailable through Mail::fake; a feature test hits the accept route with a valid signature, an expired invitation and a mismatched email, asserting the pivot row, the accepted_at stamp and the two refusals; and a tenancy test asserts a user without membership cannot access a team. composer test runs Pest in parallel and Larastan, composer cs runs Pint, and the agent runs the tests workflow's SQLite and PostgreSQL paths locally by switching DB_CONNECTION.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add team invitations to the App panel of this Filament application. Read app/Providers/Filament/AppPanelProvider.php, app/Models/Team.php, app/Models/User.php, app/Filament/App/Pages/RegisterTeam.php, the teams and team_user migrations, composer.json, phpunit.xml, tests/Pest.php, one existing Filament page test and .env.example first. Add a team_invitations migration with team, inviter, email, a hashed token, expiry, accepted_at and a unique team plus email index, a TeamInvitation model with factory, a TeamFactory, a markdown mailable with a signed accept link, and an accept route behind auth and signed middleware that attaches a matching user with syncWithoutDetaching and refuses a mismatched email or an expired token. Add a Members page in the App panel with the tenant's users, an Invite member header action with a validated email field, and a pending invitations table with resend and revoke actions. Make User::getTenants return the user's teams and canAccessTenant check membership, and override handleRegistration in RegisterTeam to attach the creator. Write Pest tests for the page action, the accept route's three cases and the tenancy check with Mail::fake, run composer test and composer cs on SQLite and PostgreSQL, and open a pull request that explains the membership change.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that adds the migration, TeamInvitation, two factories, the mailable and its markdown view, the Members page, the accept route and controller, and three test files, and edits User.php and RegisterTeam.php. The description explains the hashed token, the signed link's lifetime, and the one behaviour change outside invitations: a user now sees only teams they belong to, which the seeded pivot rows keep harmless for existing accounts.

The run's record keeps the composer test output with every Pest case named on both database drivers, the Larastan result at the project's level, and the Pint run, so a reviewer can see the accept route's refusals and the membership check passing rather than reading the controller to infer them.

Before merging, a reviewer runs the app with the local mail catcher from .env.example, invites an address from the Members page, opens the link from the caught mail while signed in as that address, and lands in the team's panel; then opens the same link again and reads the already-accepted refusal.

Run it on every Linear issue labelled teams

In the console, an automation with a linear trigger on linear.issue.labeled and the label teams starts one run per labelled issue in the Project's repository. The trigger adds the issue's text after the saved prompt, so an issue asking for a role on the invitation or for a member removal action carries that detail itself and the prompt stays fixed. Changes made by an app integration never fire it, and the automation's max_runs_per_hour bounds a burst of labelling.

From your own server, the same job is one POST /o/{org}/sessions per issue, with the repository in resources and the issue's https://linear.app/<workspace>/issue/<ID> URL beside it so Rush reads the issue through your Linear connection. A webhook_url on the API key receives run.completed or run.failed for every run that key starts, with the session_url to read the pull request link from.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

Invitations cut across a migration, a mailable, a signed route, a Livewire page and the tenancy contract, and the mistakes hide between them: a token stored in plain text, an accept route that attaches whoever is signed in, a membership check that locks the team's creator out of the team they just registered. The agent runs the Pest suite on both database drivers in its own sandbox with the mailer faked, so each of those cases is a named test rather than a hope.

Every command and its output stay with the run, so the pull request can point at the test that refused the mismatched email and the one that kept the creator in their new team, and a reviewer checks those against the record before reading a line of PHP.

Frequently asked questions

Why hash the token if the link is signed?

The signature proves the link came from the app and has not expired; the hashed token proves the row in team_invitations is the one the link was issued for, and a database read cannot be replayed as a link. Storing only the SHA-256 means a leaked table does not hand out invitations.

What happens to users who are in every team today?

Nothing. The team_user migration seeded every user into every team, so when getTenants starts returning real memberships each existing account keeps the same list. New users see only the teams that invite them or that they register.

Does the invited person need an account first?

No. The accept route sits behind auth, so a guest is sent to the App panel's login, where registration() already lets them sign up, and intended brings them back to the link. The email on the new account must match the invitation or the route refuses it.

Will the admin panel change?

No. The Members page, the route and the mailable belong to the App panel at /app. The admin panel's resources, its database notifications and its global search are untouched, and the tests for it still run in the same suite.

More Filament jobs

More jobs like this: Turn a Linear label into a PR

Keep reading