PHP code example of codelabmw / teams

1. Go to this page and download the library: Download codelabmw/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/ */

    

codelabmw / teams example snippets


createTeam([
    'name' => $name //    'description' => $description // optional, 
    'status' => $status // either 1 (active) or 2 (inactive) defaults to 1,
]): Team
 php

...
use Codelab\Teams\Traits\HasTeam;

class User extends Authenticatable
{
    HasTeam;
    ...
}
 php
    $team = $user->teams()->create([...])
    
 php
    $team = $user->createTeam([...])
    
 php

...
use Codelab\Teams\Traits\IsMember;

class User extends Authenticatable {
    IsMember;
    ...
}
 php


return [
    'member' => Your\Custom\Entity::class
];
 php
    // $member = new Your\Member\Entity
    $team->members()->attach($member);
    
 php
    $team->addMember($member->id)
    
 php
    $member->joinTeam($team->id);
    
 php

...
use Codelab\Teams\Traits\IsResource;

class Task extends Model {
    IsResource;
    ...
}
 php

...
use Codelab\Teams\Models\Team;

class CustomTeam extends Team {
    ...
}
 php


return [
    'team' => Your\Custom\Team::class
];
 php

...
use Codelab\Teams\Models\Team;

class CustomTeam extends Team {
    /**
     * Defines a has many tasks relationship on team.
     * 
     * @return MorphToMany
     */
    public function tasks(): MorphToMany
    {
        return $this->morphedByResource(Task::class);
    }
}
 php
$team->tasks()->create([...]);
 php
$team->tasks()->attach($task);
 php
teams(): MorphMany
 php
findTeam(
    $id // 
 php
deleteTeam(
    $id // 
 php
hasTeam(
    $id //
 php
members(): MorphToMany
 php
addMember(
    $id // member id, 
 php
removeMember(
    $id // member id, 
 php
hasMember(
    $id // member id, 
 php
memberTeams(): MorphToMany
 php
joinTeam(
    $id // team id, 
 php
exitTeam(
    $id // team id, 
 php
isMemberOf(
    $id // team id, 
 php
teams(): MorphToMany