PHP code example of gusmanwidodo / auth-kit-organization
1. Go to this page and download the library: Download gusmanwidodo/auth-kit-organization 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/ */
gusmanwidodo / auth-kit-organization example snippets
use Gusmanwidodo\AuthKitOrganization\OrganizationService;
$orgs = app(OrganizationService::class);
// Create an org — creator becomes owner, scoped roles are bootstrapped.
$org = $orgs->create('Acme Inc', 'App\\User', $user->id);
// Add a member with a role (grants the matching scoped role).
$orgs->addMember($org->id, 'App\\User', $other->id, 'admin');
// Authorization — delegated to auth-kit-permissions, scoped to this org.
$orgs->can($org->id, 'App\\User', $other->id, 'member.create'); // true
$orgs->can($org->id, 'App\\User', $other->id, 'organization.delete'); // false (admin)
// Invitations.
$invitation = $orgs->invite($org->id, '[email protected]', 'member');
$orgs->acceptInvitation($invitation->token, 'App\\User', $newUser->id);
use Gusmanwidodo\AuthKitOrganization\ActiveOrganization;
$active = app(ActiveOrganization::class);
$active->set($org->id);
$active->get(); // current active org id
$active->clear();
$a = $orgs->create('Org A', 'App\\User', 1); // user 1 = owner of A
$b = $orgs->create('Org B', 'App\\User', 2); // user 2 = owner of B
$orgs->can($a->id, 'App\\User', 1, 'organization.delete'); // true
$orgs->can($b->id, 'App\\User', 1, 'organization.read'); // false — no power in B
use Gusmanwidodo\AuthKitOrganization\TeamService;
$teams = app(TeamService::class);
// Create a team under an org — creator becomes lead. The creator MUST already
// be a member of the organization (nested tenancy).
$team = $teams->create($org->id, 'Engineering', 'App\\User', $user->id);
// Add another org member to the team.
$teams->addMember($team->id, 'App\\User', $other->id, 'member');
// Authorization — team-scoped, delegated to auth-kit-permissions.
$teams->can($team->id, 'App\\User', $other->id, 'team.read'); // true
$teams->can($team->id, 'App\\User', $other->id, 'team.update'); // false (member)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.