mnobre/laravel-teams

Laravel Teams is a package that provides a simple way to manage teams and their members in a Laravel application.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

pkg:composer/mnobre/laravel-teams

1.2.2 2026-02-13 00:57 UTC

This package is not auto-updated.

Last update: 2026-02-13 23:26:45 UTC


README

Laravel Teams

Laravel Teams

Lightweight, trait-based team management for Laravel — personal teams, multi-team users, invitations and simple Blade views.

Table of contents

  1. Quick overview
  2. Installation
  3. Add the trait to User model
  4. Configuration
  5. Views
  6. Routes
  7. Policies & middleware
  8. Mail & invitations
  9. API reference
  10. Publishing & customizing
  11. Tests
  12. Contributing & license
  13. Quick installation checklist

Quick overview

  • Composer package: mnobre/laravel-teams
  • Service provider auto-discovered: MNobre\\LaravelTeams\\LaravelTeamsServiceProvider
  • Views are namespaced as teams and published into resources/views/teams when the teams-views tag is published.
  • Default routes are loaded from the package routes/teams.php and use the plural from config('teams.denomination_plural') (defaults to /teams).

Installation

  1. Install via Composer:
composer require mnobre/laravel-teams
  1. Run the installer command (recommended). This publishes config, migrations, views and the routes file for you:
php artisan laravel-teams:install

The installer publishes the following tags (manual publish examples below):

  • teams-config → publishes config/teams.php
  • teams-migrations → publishes package migrations into your app database/migrations
  • teams-views → publishes views into resources/views/teams
  • teams-routes → publishes routes/teams.php into your app routes folder

After publishing migrations, run:

php artisan migrate

Add the trait to User model

Add the trait to your User model using the correct namespace:

use MNobre\\LaravelTeams\\Concerns\\HasTeams;

class User extends Authenticatable
{
    use HasTeams;
}

The trait exposes relations and helpers used throughout the package (see API reference).

Configuration

Teams Config

Edit config/teams.php to adjust:

  • denomination_singular / denomination_plural — UI labels
  • roles — available role definitions for the pivot
  • info — contact/social information used in the invitation email

After changing config run:

php artisan config:clear

Views

New TeamMember Invite (Using "Team" in config)
New TeamMember Invite
  • Package views are provided in the package and loaded under the teams view namespace.
  • Publish views using the teams-views tag to copy them into your app at resources/views/teams.
  • Example view usage: view('teams.index') or view('teams.invitations.accept', $data).

Note: the package shares a teamDenomination variable with all views (set in the service provider). Use teamDenomination['singular'] / ['plural'] in Blade templates.

Routes

  • Routes are defined in routes/teams.php inside the package and are loaded by the service provider.
  • By default most routes are protected by web and auth middleware; invitation accept/decline endpoints are public.
  • Public invitation endpoints: /invitations/accept/{token} and /invitations/decline/{token} (named team.invitations.accept / team.invitations.decline).

Policies & middleware

  • MNobre\\LaravelTeams\\Policies\\TeamPolicy is registered for the Team model in the service provider.
  • Middleware alias ensure-user-has-team is registered and points to MNobre\\LaravelTeams\\Http\\Middleware\\EnsureUserHasTeam.

Mail & invitations

  • Invitations are stored in the team_invitations table (model MNobre\\LaravelTeams\\Models\\TeamInvitation).
  • When an invitation is created the package sends MNobre\\LaravelTeams\\Mail\\TeamInvitationMail, which uses the Blade view teams.invitations.emails.team-invitation.
  • Accepting an invitation via token may create a new user (if the invited email is not yet registered), attach the user to the team, mark the invitation accepted and switch the user's current team.

Full Laravel Teams Member Invite Email

API reference

Below are the core methods implemented in the package. Use these as reference — for exact signatures check the source in src/.

HasTeams trait (attach to User)

MethodDescription
currentTeam()BelongsTo relation for the user's current team
ownedTeams()HasMany relation for teams the user owns
teams()BelongsToMany relation for memberships (pivot contains role)
personalTeam()Get the user's personal team (if present)
ownsTeam(Team $team)Check if the user owns the given team
belongsToTeam(Team $team)Check membership
switchTeam(Team $team)Set current_team_id for the user (throws if not a member)
allTeams()Return loaded collection of teams
createTeam(array $data)Create a new (non-personal) team and attach owner pivot
createPersonalTeam()Create a personal team and switch to it
teamInvitations()Relation to invitations matching the user's email

Team model (MNobre\\LaravelTeams\\Models\\Team)

MethodDescription
owner()BelongsTo owner (user)
users()BelongsToMany members (pivot role)
members()Convenience query excluding owner
isOwnedBy(User $user)Check ownership
hasUser(User $user)Check if user is a member
getRouteKeyName()Uses slug for route model binding
invitations() / pendingInvitations()Invitation relations

TeamInvitation model (MNobre\\LaravelTeams\\Models\\TeamInvitation)

MethodDescription
isPending() / isAccepted() / isDeclined() / isExpired()Invitation state helpers
accept() / decline() / markAsAccepted()Update invitation status

Controllers

  • TeamController — team CRUD and switch actions
  • TeamMemberController — add/update/remove members and send invitations
  • TeamInvitationController — accept/decline/resend/cancel invitations and track pixel opens

Publishing & customizing

Publish specific resources as needed:

php artisan vendor:publish --tag=teams-config
php artisan vendor:publish --tag=teams-migrations
php artisan vendor:publish --tag=teams-views
php artisan vendor:publish --tag=teams-routes

Edit published views under resources/views/teams and published config at config/teams.php.

Tests

Tests are located under tests/. Run the test suite with your chosen runner (Pest / PHPUnit).

Contributing & license

Contributions are welcome. See repo for contribution guidelines. Licensed under MIT.

Quick installation checklist

  1. composer require mnobre/laravel-teams
  2. php artisan laravel-teams:install (or publish tags manually)
  3. php artisan migrate
  4. Add use MNobre\\LaravelTeams\\Concerns\\HasTeams; and use HasTeams; to your User model
  5. Check if "Team" is the desired team denomination in config.teams, changing this value will take immediate effect in routes (non breaking changes, simple change "teams" to the chosen name). Examples below:
Config as "Project"Resulting Invite (Notice "Project")
Laravel Teams config as 'Project'Project invite email

Notes:

  • The package migrations include adding a current_team_id foreign key to your users table when you publish the migrations and run them.
  • The package does not provide global helper functions (such as team()); use trait relations (e.g. auth()->user()->currentTeam) or the shared view variable teamDenomination.

Personal Notes:

  • 👀 I’m interested in creating things
  • 🌱 Always learning - PHP, Laravel, Tailwind, jQuery, HTML5, CSS3, Python, Selenium, Scraping
  • 💞️ I’m looking to collaborate
  • 📫 m.nobre@ymail.com