定制 fox-run-holdings/laravel-teams 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fox-run-holdings/laravel-teams

最新稳定版本:v3.0.2

Composer 安装命令:

composer require fox-run-holdings/laravel-teams

包简介

A Laravel package for team management with invitations and role-based access control

README 文档

README

Latest Version on Packagist Total Downloads License

A comprehensive Laravel package for team management with invitations and role-based access control.

Features

  • Team Management: Create, edit, and manage teams
  • Role-Based Access Control: Owner, Admin, and Member roles
  • Team Invitations: Send and manage team invitations
  • Team Switching: Switch between teams seamlessly
  • Livewire Components: Modern, reactive UI components
  • Soft Deletes: Safe team deletion with soft deletes
  • Pagination: Built-in pagination for team listings

Installation

Prerequisites

This package requires Flux UI Pro to be installed in your Laravel application. The views and components use Flux UI Pro components.

If you haven't installed Flux UI Pro yet, please install it first:

composer require flux-ui/flux-ui-pro

1. Install the package

composer require fox-run-holdings/laravel-teams

2. Publish the configuration and views

php artisan vendor:publish --provider="FoxRunHoldings\LaravelTeams\Providers\TeamsServiceProvider"

3. Run the migrations

php artisan migrate

4. Add team relationships to your User model

Add the following methods to your App\Models\User model:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use FoxRunHoldings\LaravelTeams\Models\Team;
use FoxRunHoldings\LaravelTeams\Models\TeamInvitation;

class User extends Authenticatable
{
    // ... existing code ...

    /**
     * Get the teams that the user belongs to.
     */
    public function teams(): BelongsToMany
    {
        return $this->belongsToMany(Team::class, 'team_user')
            ->withPivot('role')
            ->withTimestamps();
    }

    /**
     * Get the team invitations for the user.
     */
    public function Invitations(): HasMany
    {
        return $this->hasMany(TeamInvitation::class, 'email', 'email');
    }

    /**
     * Get the current team of the user.
     */
    public function currentTeam()
    {
        return $this->belongsTo(Team::class, 'current_team_id');
    }

    /**
     * Check if the user has teams.
     */
    public function HasTeams(): bool
    {
        return $this->teams()->exists();
    }

    /**
     * Get the user's role in a specific team.
     */
    public function role($team_id): string
    {
        $team = $this->teams()->where('team_id', $team_id)->first();
        return $team ? $team->pivot->role : 'member';
    }

    /**
     * Get the user's initials for avatar display.
     */
    public function initials(): string
    {
        $name = explode(' ', $this->name);
        $initials = '';
        
        if (count($name) >= 2) {
            $initials = strtoupper(substr($name[0], 0, 1) . substr($name[1], 0, 1));
        } else {
            $initials = strtoupper(substr($this->name, 0, 2));
        }
        
        return $initials;
    }
}

Usage

Facade Usage

The package provides a facade for easy access to team functionality:

use FoxRunHoldings\LaravelTeams\Facades\Teams;

// Create a team
$team = Teams::create([
    'name' => 'My Team',
    'owner_id' => auth()->id(),
]);

// Find a team
$team = Teams::find(1);

// Create an invitation
$invitation = Teams::invite($team->id, 'user@example.com', 'member');

// Accept an invitation
Teams::acceptInvitation($invitation->id);

// Switch to a team
Teams::switchTeam($team->id);

// Get current team
$currentTeam = Teams::getCurrentTeam();

Livewire Components

The package provides several Livewire components that you can use in your views:

Team Invitations

<livewire:teams.invitations />

Team Management

<livewire:teams.manage />

Team Members

<livewire:teams.members />

Team Switcher

<livewire:teams.switcher />

Routes

Add the following routes to your routes/web.php:

Route::middleware(['auth'])->group(function () {
    Route::get('/teams', function () {
        return view('teams.manage');
    })->name('teams');
    
    Route::get('/teams/members', function () {
        return view('teams.members');
    })->name('teams.members');
    
    Route::get('/teams/invitations', function () {
        return view('teams.invitations');
    })->name('teams.invitations');
});

Configuration

The package configuration is published to config/teams.php. You can customize:

  • User model class
  • Available team roles
  • Invitation statuses
  • Pagination settings
  • Route configuration

Database Structure

The package creates the following tables:

  • teams - Team information
  • team_user - Many-to-many relationship between teams and users
  • team_invitations - Team invitations
  • Adds current_team_id to the users table

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This package is open-sourced software licensed under the MIT license.

Support

For support, please open an issue on GitHub or contact us at info@foxrunholdings.com.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-11