PHP code example of statix / sentra

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

    

statix / sentra example snippets


return [

    /**
     * The backed enum class that will be used to define your roles.
     */
    'roles_enum' => 'App\Enums\Roles',

    /**
     * The backed enum class that will be used to define your permissions.
     */
    'permissions_enum' => 'App\Enums\Permissions',

];



namespace App\Enums;

use Statix\Sentra\Attributes\Roles\Describe;
use Statix\Sentra\Concerns\AsRole;

enum Roles: string
{
    use AsRole;
}



namespace App\Enums;

use Statix\Sentra\Attributes\Permissions\Describe;
use Statix\Sentra\Concerns\AsPermission;

enum Permissions: string
{
    use AsPermission;
}



namespace App\Enums;

use Statix\Sentra\Attributes\Roles\Describe;
use Statix\Sentra\Concerns\AsRole;

enum Permissions: string
{
    use AsPermission;

    #[Describe(
        label: 'Create Posts', 
        description: 'Create new posts'
        roles: [
            Roles::SuperAdmin,
            Roles::Admin
        ]
    )]
    case CreatePosts = 'create-posts';

    #[Describe(
        label: 'Edit Posts', 
        description: 'Edit existing posts'
        roles: [
            Roles::SuperAdmin,
            Roles::Admin,
            Roles::StandardUser
        ]
    )]
    case EditPosts = 'edit-posts';

    #[Describe(
        label: 'Delete Posts', 
        description: 'Delete existing posts'
        roles: [
            Roles::SuperAdmin,
            Roles::Admin
        ]
    )]
    case DeletePosts = 'delete-posts';
}



namespace App\Enums;

use Statix\Sentra\Attributes\Roles\Describe;
use Statix\Sentra\Concerns\AsRole;

enum Roles: string
{
    use AsRole;

    #[Describe(
        label: 'Super Admin', 
        description: 'The highest level of access'
    )]
    case SuperAdmin;

    #[Describe(
        label: 'Admin', 
        description: 'Admin level access'
    )]
    case Admin = 'admin';

    #[Describe(
        label: 'Standard User', 
        description: 'Standard user access'
    )]
    #[Describe('User')]
    case StandardUser = 'user';
}
bash
php artisan vendor:publish --tag="sentra"