---
title: "Models & schema — Teams for Laravel | Roundly"
description: "The six tables and models, swapping in your own model subclasses, and replacing the role provider."
url: https://roundly-consulting.com/open-source/docs/teams-for-laravel/models-and-schema
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Teams for Laravel](https://roundly-consulting.com/open-source/docs/teams-for-laravel.md)

# Models & schema

Six tables back six models. All six are soft-deletable, and Team, Member, Invite and JoinRequest cast meta to a Collection; mass assignment is open because the facade and its actions are the intended write path:

| Table | Model | Key columns |
| --- | --- | --- |
| `teams` | Team | name, is\_public, owner morph (nullable), meta json |
| `team_members` | Member | team\_id, member morph, role, accepted\_invite\_id (null on invite delete), meta, expires\_at (indexed) — unique on (team\_id, member morph), soft-deleted rows included |
| `team_invites` | Invite | team\_id, code (unique), role, email (indexed), invited\_by morph, meta, uses, max\_uses, expires\_at |
| `team_join_requests` | JoinRequest | team\_id, requester morph, requested\_role, status (indexed), message, meta, responded\_by morph, responded\_at, expires\_at |
| `team_roles` | RoleDefinition | key (unique), name, permissions json, description — the database role driver |
| `team_role_overrides` | TeamRole | team\_id, key, name, permissions json, description — unique on (team\_id, key) |

Every table referencing teams cascades when a team row is force-deleted. The morph columns follow key\_type — see Configuration.

## Swapping a model

Point a teams.models.\* key at your own subclass — every relation and action resolves the class through config. The class must be the packaged model or a subclass of it; anything else throws an InvalidConfigurationException naming the key — it is never silently replaced by the packaged one:

```php
namespace App\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use RoundlyConsulting\Teams\Models\Team as BaseTeam;

class Team extends BaseTeam
{
    public function projects(): HasMany
    {
        return $this->hasMany(Project::class);
    }
}
```

```php
// config/teams.php
'models' => [
    'team' => App\Models\Team::class,
    'member' => RoundlyConsulting\Teams\Models\Member::class,
    'invite' => RoundlyConsulting\Teams\Models\Invite::class,
    'team_role' => RoundlyConsulting\Teams\Models\TeamRole::class,
    'join_request' => RoundlyConsulting\Teams\Models\JoinRequest::class,
],
```

## A custom role provider

To load roles from somewhere else — an external service, say — rebind the RoleProvider contract after the package registers, for example in your AppServiceProvider’s register(). The package binds it scoped; bind yours scoped too, so a provider that memoises its role map is rebuilt for every request and queued job:

```php
// app/Providers/AppServiceProvider.php → register()
use RoundlyConsulting\Teams\Roles\Contracts\RoleProvider;

// Scoped, like the package's own binding: a fresh provider per request or queued job.
$this->app->scoped(RoleProvider::class, fn () => new \App\Teams\MyRoleProvider());
```

```php
namespace RoundlyConsulting\Teams\Roles\Contracts;

interface RoleProvider
{
    /**
     * Define a role — an upsert on $key: registering a key again replaces its
     * name, permissions and description, whichever provider backs it.
     *
     * @param  list<string|Permission>  $permissions
     */
    public function register(string $key, string $name, array $permissions = [], string $description = ''): Role;

    public function find(string $key): ?Role;

    /** @return array<string, Role> */
    public function all(): array;
}
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/teams-for-laravel.md)
