Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel

How to Disable Team Creation in Laravel Jetstream

When using Laravel Jetstream with teams, you might want to prevent users from creating new teams while still allowing them to be members of multiple teams through invitations. Here's how to implement this pattern.

The Solution

Modify the create method in app/Policies/TeamPolicy.php:

public function create(User $user): bool
{
    // Only allow team creation if the user has no teams
    // This effectively limits users to their initial personal team
    return $user->allTeams()->count() === 0;
}

This change will:

  • Give each user their personal team during registration
  • Prevent users from manually creating additional teams
  • Still allow users to be members of multiple teams through invitations
  • Maintain all other team-based features

How It Works

When a user registers, Jetstream automatically creates their personal team. With our TeamPolicy modification:

  1. The UI automatically hides team creation options through Jetstream's built-in v-if="$page.props.jetstream.canCreateTeams" checks
  2. Direct attempts to access /teams/create will return a 403 Forbidden response
  3. Users can still be members of:
    • Their personal team (created during registration)
    • Any number of teams they've been invited to join
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *