PHP code example of tripteki / laravelphp-acl

1. Go to this page and download the library: Download tripteki/laravelphp-acl 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/ */

    

tripteki / laravelphp-acl example snippets



/**
 * @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,
];

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", ]); //

php artisan vendor:publish --tag=tripteki-laravelphp-acl

php artisan vendor:publish --tag=tripteki-laravelphp-acl-migrations

php artisan migrate

php artisan queue:work

php artisan vendor:publish --tag=tripteki-laravelphp-acl-tests