PHP code example of jurager / teams

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

    

jurager / teams example snippets


 

namespace App\Providers;

use Jurager\Teams\Traits\HasTeams;

class User extends Model {

    use HasTeams;
}

// Access the team's owner...
$team->owner

// Get all the team's users, excluding owner
$team->users()

// Get all the team's users, including the owner...
$team->allUsers()

// Determine if the given user is a team member...
// Accepts user object
$team->hasUser($user)

// Adds a user to the team with a specified role by role ID or code
$team->addUser($user, $role_keyword)

// Update the role of a specific user within the team
$team->updateUser($user, $role_keyword)

// Remove the given user from the team.
$team->deleteUser($user);

// Get all the abilities belong to the team.
$team->abilities()

// Get all the team's roles.
$team->roles()

// Return the user role object from the team
$team->userRole($user)

// Check if the team has a specific role by ID or code or any roles at all if null
$team->hasRole($role_keyword)

// Get the role from the team by role id or code 
$team->getRole($role_keyword)

// Add new role to the team
$team->addRole($code, $permissions, $name, $description)

// Update the role in the team
// Name and description is nullable when no changes needed
$team->updateRole($role_keyword, $permissions, $name, $description)

// Deletes the given role from team
$team->deleteRole($role_keyword)

// Get all groups of the team.
$team->groups()

// Get team group by its id or code
$team->getGroup($group_keyword)

// Add new group to the team
$team->addGroup($code, $permissions, $name)

// Update the group in the team
$team->updateGroup($group_keyword, $permissions, $name)

// Delete group from the team
$team->deleteGroup($group_keyword)

// Determine if the team has a member with the given email address...
$team->hasUserWithEmail($email)

// Determine if the given user is a team member with the given permission...
// $

// Access the teams that a user belongs to...
$user->teams

// Access all of a user's owned teams...
$user->ownedTeams

// Access all the team's (including owned teams) that a user belongs to...
$user->allTeams()

// Determine if a user owns a given team...
$user->ownsTeam($team)

// Determine if a user belongs to a given team...
$user->belongsToTeam($team)

// Get the role that the user is assigned on the team...
$user->teamRole($team)

// Determine if the user has the given role (or roles if array passed) on the given team...
// $e permission in the array are for user to action on certain model, used in case if global ability or role allowing this action
$user->forbidTeamAbility($team, 'server:edit', $server)

$team = new Team();

$team->name = 'Example Team';
$team->user_id = $user->id;

if ($team->save()) {

    $team->addRole('admin', [
        'employees.*',
        'sections.*',
        'articles.*',
        'tags.*',
        'comments.*',
        'team.edit',
        'stores.*',
        'plan.edit',
    ]);
    
    $team->addRole('user', [
        'employees.view',
        'articles.view',
        'articles.add',
        'sections.view',
        'sections.add',
        'comments.add',
        'tags.view',
        'stores.add',
        'stores.delete',
        'tags.add',
    ]);
}

return $user->hasTeamPermission($team, 'server:update');

$user->allowTeamAbility($team, $action, $action_entity, $target_entity)

User::hasTeamAbility($team, 'edit_post', $post);

User::forbidTeamAbility($team, $action, $action_entity,$target_entity)

// Add new group to the team
// If $name is null, str::studly of $code will be used
$team->addGroup($code, $permissions, $name)

// Update the group in the team, if permissions is empty array all exiting permissions will be detached
// If $name is null, str::studly of $code will be used
$team->updateGroup($group_keyword, $permissions, $name)

// Delete group from the team
$team->deleteGroup($group_keyword)

// Get all groups of the team.
$team->groups();

// Check if the team has a specific group by ID or code or any groups at all if null passed
$team->hasGroup($group_keyword)

// Get team group by its code
$group = $team->getGroup($group_keyword);

// Get all group users
$group->users();

// Attach users or user to a group
$group->attachUser($user);

// Detach users or user from group
$group->detachUser($user);

Route::group(['prefix' => 'admin', 'middleware' => ['role:admin,team_id']], function() {
    Route::get('/users', 'UserController@usersIndex');
    Route::get('/user/edit', ['middleware' => ['permission:edit-users,team_id'], 'uses' => 'UserController@userEdit']);
});

Route::get('/{team_id}/users', ['middleware' => ['permission:views-users'], 'uses' => 'CommonController@commonUsers']);

'middleware' => ['role:admin|root,{team_id}']

'middleware' => ['role:admin|root,{team_id}']
// $user->hasTeamRole($team, ['admin', 'root']);

'middleware' => ['permission:edit-post|edit-user,{team_id}']
// $user->hasTeamPermission($team, ['edit-post', 'edit-user']);

'middleware' => ['role:admin|root,{team_id},t'], r,{team_id},], 

'middleware' => ['ability:edit,App\Models\Article,{article_id}']
// $user->hasTeamAbility($team, 'edit', $article);
sh
php artisan teams:install
sh
php artisan migrate