tripteki/laravelphp-acl

Trip Teknologi's Laravel.php ACL

1.0.0 2023-02-01 08:13 UTC

This package is auto-updated.

Last update: 2023-02-01 08:15:14 UTC


README

This package provides wrapper of an implementation Access Control List (ACL) Roles-Permissions in repository pattern for Lumen and Laravel.

Getting Started

Installation :

$ composer require tripteki/laravelphp-acl

How to use it :

  • Read the instruction for Lumen or Laravel.

  • Put Tripteki\ACL\Providers\ACLServiceProvider to service provider configuration list.

  • Publish config file in the root of your project's directory with running :

php artisan vendor:publish --tag=tripteki-laravelphp-acl
  • Put Tripteki\ACL\Traits\RolePermissionTrait to auth's provider model.

  • Put TargetModel::observe(\Tripteki\ACL\Observers\OwnObserver::class) in provider.

  • Put below to the middleware :

"role" => \Tripteki\ACL\Http\Middleware\RoleMiddleware::class
"permission" => \Tripteki\ACL\Http\Middleware\PermissionMiddleware::class
"role_or_permission" => \Tripteki\ACL\Http\Middleware\RoleOrPermissionMiddleware::class

  • Migrate.
$ php artisan migrate
  • Sample :
use Tripteki\ACL\Contracts\Repository\Admin\IACLRoleRepository;
use Tripteki\ACL\Contracts\Repository\Admin\IACLPermissionRepository;
use Tripteki\ACL\Contracts\Repository\IACLRepository;

$roleRepository = app(IACLRoleRepository::class);
$permissionRepository = app(IACLPermissionRepository::class);

// $permissionRepository->rule("edit:posts.*"); //
// $permissionRepository->unrule("edit:posts.*"); //
// $permissionRepository->get("edit:posts.*"); //
// $permissionRepository->all(); //

// $roleRepository->rule("admin"); //
// $roleRepository->rule("user"); //
// $roleRepository->unrule("admin"); //
// $roleRepository->unrule("user"); //
// $roleRepository->get("admin"); //
// $roleRepository->get("user"); //
// $roleRepository->all(); //

// $roleRepository->setRole($roleRepository->get("admin")); //
// $roleRepository->getRole(); //
// $roleRepository->grant("edit:posts.*"); //
// $roleRepository->revoke("edit:posts.*"); //
// $roleRepository->ability("edit:posts"); //
// $roleRepository->permissions(); //

$repository = app(IACLRepository::class);
// $repository->setUser(...); //
// $repository->getUser(); //

// $repository->grantAs("user"); //
// $repository->revokeAs("user"); //
// $repository->is("user"); //
// $repository->grant("edit:posts.1"); //
// $repository->revoke("edit:posts.1"); //
// $repository->can("edit:posts.1"); //
// $repository->permissions(); //
// $repository->owns(); //

Author