Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattCast44 committed Dec 13, 2024
1 parent ebe6095 commit 6bc62f1
Showing 1 changed file with 132 additions and 4 deletions.
136 changes: 132 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Sentra for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/statix/roles-and-permissions.svg?style=flat-square)](https://packagist.org/packages/statix/roles-and-permissions)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/statix/sentra.svg?style=flat-square)](https://packagist.org/packages/statix/sentra)

[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/statix/roles-and-permissions/run-tests?label=tests)]()
A lightweight Laravel roles and permissions package using Backed Enums.

## Installation

Expand All @@ -12,7 +12,7 @@ You can install the package via composer:
composer require statix/sentra
```

You can publish the config file with:
You should publish the config file with the following command:

```bash
php artisan vendor:publish --tag="sentra"
Expand All @@ -22,14 +22,142 @@ This is the contents of the published config file:

```php
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',

];
```

## Usage

To get started, create two string backed Enums - one of your roles and one for your permissions.

```bash
php artisan make:enum "App\Enums\Roles" --string
php artisan make:enum "App\Enums\Permissions" --string
```

If you create your enums in a different namespace or different name, be sure to update the `roles_enum` and `permissions_enum` in the `sentra.php` config file.


Then add the `AsRole` trait to your `Roles` enum.

```php
<?php

namespace App\Enums;

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

enum Roles: string
{
use AsRole;
}
```

And add the `AsPermission` trait to your `Permissions` enum.

```php
<?php

namespace App\Enums;

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

enum Permissions: string
{
use AsPermission;
}
```

You are now ready to start defining your roles and permissions.

```php
<?php

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';
}
```

```php
<?php

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';
}
```

## Testing
Expand Down

0 comments on commit 6bc62f1

Please sign in to comment.