PHP code example of cleaniquecoders / laravel-organization
1. Go to this page and download the library: Download cleaniquecoders/laravel-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/ */
cleaniquecoders / laravel-organization example snippets
use CleaniqueCoders\LaravelOrganization\Actions\CreateNewOrganization;
use CleaniqueCoders\LaravelOrganization\Enums\OrganizationRole;
// Create an organization
$organization = (new CreateNewOrganization())->handle($user);
// Add members
$organization->addUser($user, OrganizationRole::ADMINISTRATOR);
$organization->addUser($member, OrganizationRole::MEMBER);
// Configure settings
$organization->setSetting('app.timezone', 'America/New_York');
$organization->setSetting('features.api_access', true);
$organization->save();
use CleaniqueCoders\LaravelOrganization\Concerns\InteractsWithUserOrganization;
use CleaniqueCoders\LaravelOrganization\Contracts\UserOrganizationContract;
class User extends Authenticatable implements UserOrganizationContract
{
use InteractsWithUserOrganization;
protected $fillable = ['name', 'email', 'password', 'organization_id'];
}
// Now you can:
$user->organizations; // Get all user's organizations
$user->currentOrganization; // Get current organization
$user->ownedOrganizations; // Get organizations user owns
$user->belongsToOrganization($id); // Check membership
$user->isAdministratorOf($id); // Check admin role