PHP code example of timedoor / laravel-role-js

1. Go to this page and download the library: Download timedoor/laravel-role-js 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/ */

    

timedoor / laravel-role-js example snippets


return [
    'generator' => timedoor\RoleJs\Generator\JeremyKenedyRoleGenerator::class,
];



namespace App\RoleJs;

use timedoor\RoleJs\Generator\GeneratorInterface;

class CustomRoleGenerator implements GeneratorInterface
{
    /**
     * @return \Illuminate\Support\Collection<int, string>
     */
    public function getRoles()
    {
        return collect(['admin', 'editor']);
    }

    /**
     * @return \Illuminate\Support\Collection<int, string>
     */
    public function getPermissions()
    {
        return collect(['view.users', 'edit.users']);
    }

    /**
     * @return \Illuminate\Support\Collection<string, string[]>
     */
    public function getRolePermissions()
    {
        return collect([
            'admin' => ['view.users', 'edit.users'],
            'editor' => ['view.users'],
        ]);
    }
}

return [
    'generator' => App\RoleJs\CustomRoleGenerator::class,
];
bash
php artisan vendor:publish --tag="laravel-role-js-config"
bash
php artisan role-js:publish
bash
php artisan role-js:publish your/publish/path/roles
bash
php artisan role-js:generate
bash
php artisan role-js:generate your/publish/path/roles