muhammadtashfeen/lara-authpem

A package that makes settings permissions and authorizations easier in Laravel.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/muhammadtashfeen/lara-authpem

v1.0.1 2025-08-17 20:28 UTC

This package is auto-updated.

Last update: 2025-12-17 21:17:20 UTC


README

LaraAuthpem is a Laravel package for flexible role & permission management, bringing attribute-based access control to your Laravel applications.
With LaraAuthpem, you can easily protect routes, controllers, and actions by simply attaching PHP attributes. ๐Ÿ›ก๏ธ

Tests

โœจ Features

  • ๐Ÿ”‘ Assign multiple roles & permissions to users
  • โšก Middleware for automatic role & permission checks
  • ๐Ÿงฉ Attribute-based access control with PHP 8+ attributes
  • ๐Ÿ”’ Protect routes and controllers with minimal boilerplate
  • ๐Ÿ› ๏ธ Simple integration with Laravel authentication
  • ๐Ÿ“ฆ Service classes to handle role & permission logic

๐Ÿ“ฆ Installation

Install via Composer:

composer require muhammadtashfeen/lara-authpem

(Optional) Publish the service provider:

php artisan vendor:publish --provider="MuhammadTashfeen\LaraAuthpem\Providers\AuthServiceProvider"

๐Ÿ”‘ User Model Requirements

Your User model must implement the following methods:

public function getRoles(): array
{
    return ['admin', 'editor']; // example
}

public function getPermissions(): array
{
    return ['view_users', 'create_users']; // example
}

โšก How these arrays are populated is entirely up to you โ€” they can come from the database, config, or any custom logic.
The important part is that they always return arrays of role names and permission names.

๐Ÿš€ Usage

๐Ÿ›ก๏ธ Middleware Protection

Use the middleware alias mt.authpem to protect routes:

Route::middleware(['mt.authpem'])->group(function () {
    Route::get('/users', [UserController::class, 'index']);
});

๐Ÿงฉ Attribute Usage (Controller-Level)

use MuhammadTashfeen\LaraAuthpem\Attributes\HasRole;
use MuhammadTashfeen\LaraAuthpem\Attributes\HasPermission;

#[HasRole('admin')]
#[HasPermission('view_users')]
public function index() {
    // Only accessible by admins with view_users permission
}

๐Ÿงช Testing

Run PHPUnit tests:

vendor/bin/phpunit

โš™๏ธ Compatibility

  • PHP: ^8.3
  • Laravel: 10.x
  • PHPUnit: ^11.0 (for testing)
  • Orchestra Testbench: ^9.5 (for testing)
  • Laravel Pint: dev-main (optional, for code style)

๐Ÿค Contributing

Contributions are welcome!
Feel free to open issues or submit PRs to improve LaraAuthpem.

๐Ÿ“„ License

LaraAuthpem is open-sourced software licensed under the MIT license.