1. Go to this page and download the library: Download litepie/teams library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Litepie\Teams\Actions\AddTeamMemberAction;
// Add a member with specific role
AddTeamMemberAction::execute($team, [
'user_id' => $user->id,
'role' => 'member',
'permissions' => ['view_team', 'create_posts'],
], $teamOwner);
// Invite via email
use Litepie\Teams\Actions\InviteTeamMemberAction;
InviteTeamMemberAction::execute($team, [
'email' => '[email protected]',
'role' => 'member',
'message' => 'Welcome to our team!',
], $teamOwner);
// Set tenant context
tenancy()->initialize($tenant);
// All team operations are now scoped to the current tenant
$teams = Team::current()->get(); // Only returns current tenant's teams
// Create tenant-specific team
$team = CreateTeamAction::execute(null, [
'name' => 'Tenant Development Team',
'tenant_id' => tenancy()->current()?->id,
], $user);
// Team permissions are automatically tenant-scoped
$user->can('manage', $team); // Checks within current tenant context
use Litepie\Teams\Workflows\TeamWorkflow;
// Team lifecycle workflow
$workflow = TeamWorkflow::create();
// Available states: draft, active, suspended, archived
// Available transitions: activate, suspend, archive, restore
// Transition team through workflow
$team->transitionTo('active', [
'activated_by' => $user->id,
'reason' => 'Team setup completed',
]);
// Check current state
if ($team->getCurrentState()->getName() === 'active') {
// Team is active
}
// Team-level permissions
$team->addMember($user, 'admin');
$team->addMember($user, 'member');
// Check team-specific permissions
if ($team->userHasRole($user, 'admin')) {
// User is an admin of this team
}
if ($team->userHasPermission($user, 'edit_team_settings')) {
// User can edit team settings
}
// Update member role
$team->updateMemberRole($user, 'moderator');
// Update member permissions
$team->updateMemberPermissions($user, ['edit_content', 'manage_files']);
// API routes are automatically registered
Route::middleware(['api', 'tenant.ce('teams.members', TeamMemberController::class);
Route::apiResource('teams.invitations', TeamInvitationController::class);
});
// API Resources
$team = Team::find(1);
return new TeamResource($team);
// Returns: team data with members, files, permissions, etc.
// Listen to team events
Event::listen(TeamCreated::class, function ($event) {
// Send welcome notifications
NotifyTeamCreated::dispatch($event->team);
});
Event::listen(MemberJoinedTeam::class, function ($event) {
// Update team analytics
UpdateTeamMetrics::dispatch($event->team);
});
// Real-time broadcasting
class MemberJoinedTeam implements ShouldBroadcast
{
public function broadcastOn()
{
return new PrivateChannel("team.{$this->team->id}");
}
}
use Litepie\Teams\Testing\TeamTestHelpers;
class TeamFeatureTest extends TestCase
{
use TeamTestHelpers;
public function test_user_can_create_team()
{
$user = User::factory()->create();
$tenant = $this->createTenant();
$this->actingAsTenant($tenant)
->actingAs($user);
$team = $this->createTeam([
'name' => 'Test Team',
'owner_id' => $user->id,
]);
$this->assertDatabaseHas('teams', [
'name' => 'Test Team',
'tenant_id' => $tenant->id,
]);
$this->assertTrue($user->ownsTeam($team));
}
}