triotechnology/laravel-permission

Laravel Policy integration with spatie/laravel-permission

1.0.2 2025-03-06 01:11 UTC

This package is auto-updated.

Last update: 2025-07-01 00:12:44 UTC


README

Latest Version on Packagist Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require triotechnology/laravel-permission

You can publish the config file with:

php artisan vendor:publish --tag="laravel-permission-config"

Usage

Use the provided Triotechnology\Permission\Policies\Policy class as a base class for your policies.

<?php

namespace App\Policies;

use TrioTechnology\Permission\Policies\Policy as BasePolicy;

class UserPolicy extends BasePolicy {}

Add a Permission enum to your project under the App\Permissions namespace with the name <Model>Permission.

The cases of the enum should follow camelCase and the values should follow some consistent pattern e.g. <model>.<action>.

The base policy follows standard Laravel action names, with some extras added for convenience.

<?php

namespace App\Permissions;

enum UserPermission: string 
{
    case viewAny = 'users.view_any';
    case view = 'users.view';
    case create = 'users.create';
    case update = 'users.update';
    case delete = 'users.delete';
    case forceDelete = 'users.force_delete';
    
    // Extra actions
    case forceDeleteAny = 'users.force_delete_any';
    case restore = 'users.restore';
    case reorder = 'users.reorder';
    case replicate = 'users.replicate';
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

  • William Bell

License

The MIT License (MIT). Please see License File for more information.