PHP code example of ibrostudio / laravel-teamable

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

    

ibrostudio / laravel-teamable example snippets


namespace App\Models;

use IBroStudio\Teamable\Concerns\IsTeamable;
use Illuminate\Database\Eloquent\Model;

class Company extends Model implements \IBroStudio\Teamable\Contracts\Teamable
{
    use IsTeamable;
}

namespace App\Models;

use IBroStudio\Teamable\Concerns\HasTeams;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasTeams;
}

'model_name_attribute' => [
    'default' => 'name',
    Company::class => 'company_name'
],

$company = Company::create([
    'name' => 'iBroStudio',
]);

$company->team; // This give access to the team model through a MorphOne relationship

$company->createTeam();

$company->team; // This give access to the team model

$user->attachTeam($company->team);

$user->attachTeam($company_1->team);
$user->attachTeam($company_2->team);

$department = Department::create([
    'name' => 'Development',
]);
$user->attachTeam($department->team);

$user->getCurrentTeamId(TeamType::make(Company::class));
// or $user->getCurrentTeamId($company_1->team->type);

$user->getCurrentTeamId(TeamType::make(Department::class));

$user->switchToTeam($company_2->team);

$user->detachTeam($company->team);
bash
php artisan data-repository:install