tripteki / laravelphp-acl
Trip Teknologi's Laravel.php ACLs
2.0.5
2024-10-19 10:55 UTC
Requires
- php: ^8.0.2
- spatie/laravel-permission: ^6.9.0
- tripteki/laravelphp-adminer: ^1.0.0
- tripteki/laravelphp-helpers: ^1.0.0
- tripteki/laravelphp-import-export: ^1.0.0
- tripteki/laravelphp-repository: ^1.0.0
- tripteki/laravelphp-request-response-query: ^1.0.0
Suggests
- laravel/framework: Required when using laravel framework (^9.0).
- laravel/lumen-framework: Required when using lumen framework (^9.0).
README
This package provides implementation of Access Control List (ACL) Roles-Permissions in repository pattern for Lumen and Laravel besides REST API starterpack of admin management with no intervention to codebase and keep clean.
Getting Started
Installation :
composer require tripteki/laravelphp-acl
How to use it :
/** * @return array<string, string> */ protected $dispatchesEvents = [ "created" => \Tripteki\ACL\Events\Created::class, "deleted" => \Tripteki\ACL\Events\Deleted::class, "restored" => \Tripteki\ACL\Events\Created::class, "forceDeleted" => \Tripteki\ACL\Events\Deleted::class, ];
-
Put
Tripteki\ACL\Providers\ACLServiceProvider
to service provider configuration list. -
Put
Tripteki\ACL\Providers\ACLServiceProvider::ignoreConfig()
intoregister
provider, then publish config file into your project's directory with running :
php artisan vendor:publish --tag=tripteki-laravelphp-acl
- Put
Tripteki\ACL\Providers\ACLServiceProvider::ignoreMigrations()
intoregister
provider, then publish migrations file into your project's directory with running (optionally) :
php artisan vendor:publish --tag=tripteki-laravelphp-acl-migrations
- Migrate.
php artisan migrate
- Emit Event-Listener.
php artisan queue:work
- Publish tests file into your project's directory with running (optionally) :
php artisan vendor:publish --tag=tripteki-laravelphp-acl-tests
- 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); /* * As `{resource}`.`{action}`.`{target}` is representing : * * - {resource} : 'posts' = 'posts.*' = 'posts.*.*' * - {action} : 'viewAny', 'view', 'create', 'update', 'delete' * - {target} : '[identifier]' */ // $permissionRepository->rule("posts.update.*"); // // $permissionRepository->unrule("posts.update.*"); // // $permissionRepository->get("posts.update.*"); // // $permissionRepository->all(); // // $roleRepository->rule("admin"); // // $roleRepository->rule("user"); // // $roleRepository->unrule("admin"); // // $roleRepository->unrule("user"); // // $roleRepository->get("admin"); // // $roleRepository->get("user"); // // $roleRepository->all(); // // $roleRepository->forRole("admin"); // // $roleRepository->grant("posts.update.*"); // // $roleRepository->revoke("posts.update.*"); // // $roleRepository->ability("posts.update.*"); // // $roleRepository->permissions(); // $repository = app(IACLRepository::class); // $repository->setUser(...); // // $repository->getUser(); // // $repository->grantAs("admin"); // // $repository->revokeAs("admin"); // // $repository->is("admin"); // // $repository->permissions(); // // $repository->grant("posts.update.5"); // // $repository->revoke("posts.update.5"); // // $repository->owns(); // // $repository->owns(\App\Models\Post::class, 5); // // $repository->can(iacl(\App\Models\Post::class, "update", 5)); // // $repository->can("posts.update.5"); // // auth()->user()->can("posts.update.5"); // // auth()->user()->canAny([ "posts.update.5", ]); // // auth()->user()->cant("posts.update.5"); // // auth()->user()->cantAny([ "posts.update.5", ]); //
- Generate swagger files into your project's directory with putting this into your annotation configuration (optionally) :
base_path("app/Http/Controllers/ACL")
base_path("app/Http/Controllers/Admin/ACL")
Usage
php artisan adminer:install:acl
Author
- Trip Teknologi (@tripteki)
- Hasby Maulana (@hsbmaulana)