rockbuzz/lara-memberships

Account member management

0.1.0 2021-05-22 15:25 UTC

This package is auto-updated.

Last update: 2022-06-22 17:55:33 UTC


README

Account member management

badge.svg

Requirements

PHP >=7.2

Install

$ composer require rockbuzz/lara-memberships
$ php artisan vendor:publish --provider="Rockbuzz\LaraMemberships\ServiceProvider"
$ php artisan migrate

config/memberships.php

...
'rbac' => [
    /* 'admin' => [
        '*'
    ],
    'editor' => [
        '*.create',
        '*.update',
        'posts.delete'
    ] */
]

Add the HasMemberships attribute to the user model

Usage

use Rockbuzz\LaraMemberships\Account;

class User
{
    use HasMemberships
}
$user->ownedAccounts(): HasMany;
$user->accounts(): BelongsToMany;
$user->allAccounts(): Collection;
$user->accountRole(Account $account): Role;
$user->hasAccountRole(Account $account, string $role): bool;
$user->accountPermissions($account): string[];
$user->hasAccountPermission(Account $account, string $permission): bool;
$user->ownsAccount(Account $account): bool;
$account->owner(): User;
$account->members(): BelongsToMany;
$account->findMemberById(int $id): User;
$account->addMember(User $user, Role $role = null): self;

Development environment

Requirements

Usage

docker-compose up -d --build
docker-compose exec app composer ...

Style Code

composer cs

Testing

composer test

License

The Lara Memberships is open-sourced software licensed under the MIT license.