Workspaces vs Tenants
Understanding the hierarchy:- Tenant: Top-level isolation (separate databases, accessed via subdomain)
- Workspace: Logical separation within a tenant (same database, filtered by workspace_id)
While tenants have complete database isolation, workspaces share the same database but maintain logical separation through workspace-scoped queries.
Workspace Model
TheApp\Models\Workspace model (app/Models/Workspace.php:65) defines workspace properties:
Creating Workspaces
Using CreateWorkspaceAction
Workspaces are created using theCreateWorkspaceAction (app/Actions/CreateWorkspaceAction.php):
Provide Workspace Details
Required information:
- Name (automatically generates slug)
- Owner (user who will own the workspace)
- Optional: description, address, phone
Workspace is Created
The action creates the workspace and automatically:
- Generates a unique slug from the name
- Sets the creator as the owner
- Marks the workspace as active
Via API/Controller
The workspace creation flow is handled by workspace controllers inapp/Http/Controllers/.
Workspace Isolation
Data is isolated by workspace through several mechanisms:Database Scoping
Most models are scoped to the current workspace:Global Scopes
Many models apply automatic workspace filtering when queried in a workspace context.User-Workspace Assignments
Assigning Users to Workspaces
Users can belong to multiple workspaces within a tenant:Workspace Roles
Users have roles within each workspace (stored in pivot table):- owner: Full control over workspace
- admin: Administrative access
- member: Standard user access
- Custom roles can be defined
Workspace roles are separate from global user roles. A user can be an admin in one workspace and a member in another.
Workspace Switching
Users can switch between their assigned workspaces:Current Workspace
Each user has acurrent_workspace_id that determines their active workspace:
Using SwitchWorkspaceAction
The recommended way to switch workspaces:- Verifies user has access to the workspace
- Updates
current_workspace_id - Clears workspace-specific cache
- Updates user session
Managing Workspace Members
Adding Members
Removing Members
Workspace Settings
Workspaces can store custom settings in thesettings JSON column:
Workspace-Specific Configurations
Document Subtypes
Workspaces can have preferred document subtypes (NCF sequences):Company Details
While company details are tenant-wide in the current implementation, they’re typically used within workspace context for invoices and documents. See Company Details Configuration for more information.Deleting Workspaces
Using DeleteWorkspaceAction
Best Practices
- Naming Convention: Use clear, descriptive workspace names (e.g., “Main Office”, “Warehouse - North”)
- Access Control: Regularly audit workspace member lists
- Default Workspace: Set a sensible default workspace for new users
- Workspace Scoping: Always filter queries by workspace when appropriate
- Settings Management: Document custom workspace settings in code comments
Related Resources
- Multi-Tenancy Architecture - Understanding tenant isolation
- User Roles & Permissions - Managing access control
- Company Details - Workspace-level company information