Skip to main content

Overview

The teams table is the foundation of the multi-tenancy system. Each team represents a tenant in your application.

Schema

Columns

id (Primary Key)

  • Type: BIGINT UNSIGNED
  • Description: Unique identifier for the team
  • Auto-increment: Yes

name

  • Type: VARCHAR(255)
  • Description: Team name (e.g., “Acme Corporation”)
  • Required: Yes
  • Example: “Marketing Agency”, “Development Team”

description

  • Type: TEXT
  • Description: Optional team description
  • Required: No
  • Example: “Our main development team”

owner_id

  • Type: BIGINT UNSIGNED
  • Description: Foreign key to the user who owns this team
  • Required: Yes
  • Constraints:
    • Foreign key to users.id
    • Cascade on delete (if owner is deleted, team is deleted)

created_at / updated_at

  • Type: TIMESTAMP
  • Description: Laravel timestamps
  • Automatically managed: Yes

Relationships

Owner (BelongsTo)

Each team belongs to one owner:

Users/Members (BelongsToMany)

Teams have many members through the team_user pivot table:

Usage Examples

Creating a Team

Querying Teams

Updating a Team

Deleting a Team

Indexes

Consider adding these indexes for better performance:

Optional Enhancements

Adding a Slug

For prettier URLs:

Adding Team Settings

Store team-specific settings as JSON:

Next Steps