apurba-labs/laravel-iam

Laravel IAM (Identity & Access Management) package with hierarchical permissions, wildcard support, and SaaS-ready design.

Maintainers

Package info

github.com/apurba-labs/laravel-iam

pkg:composer/apurba-labs/laravel-iam

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-04-02 20:51 UTC

This package is auto-updated.

Last update: 2026-04-02 22:11:44 UTC


README

Latest Version on Packagist Total Downloads License

A powerful, context-aware Identity and Access Management (IAM) system for Laravel. Inspired by AWS IAM, built for modern SaaS architectures.

🚀 Key Features

  • Contextual Scopes: Assign roles to users for specific branches or tenants.
  • Wildcard Logic: Support for resource.*, *.action, and *.* overrides.
  • Action Aliasing: Built-in manage capability (grants all actions for a resource).
  • Developer Friendly: Dynamic Resource & Action registration.
  • Performance First: Built-in caching for permission resolution.

📦 Installation

Install the package via composer:

composer require apurba-labs/laravel-iam

Publish and run the migrations:

php artisan vendor:publish --tag="iam-migrations"
php artisan migrate

🛠 Usage

1. Setup your Model

Add the trait and contract to your User.php:

use ApurbaLabs\IAM\Traits\HasRoles;
use ApurbaLabs\IAM\Contracts\Authorizable;

class User extends Authenticatable implements Authorizable {
    use HasRoles;
}

2. Registration Resources

Register your modules in `AppServiceProvider.php`:

```php
public function boot() {
    IAM::registerResources([
        'inventory' => 'Stock Management',
        'payroll'   => 'Employee Salary'
    ]);

    IAM::registerActions(['submit', 'approve']);
}

3. Syncing to Database

php artisan iam:sync

🔍 4. Checking Permissions (The Logic)

## Checking Permissions

### Via Facade
```php
// Global check
IAM::can($user, 'inventory.view');

// Scoped check (e.g., for Branch ID 101)
IAM::can($user, 'inventory.view', 101);

Via Middleware

The middleware automatically detects the scope from the X-Scope-ID header.

// Single permission
Route::middleware('iam:inventory.view')->get('/inventory', ...);

// Multiple permissions (OR logic)
Route::middleware('iam:payroll.edit|payroll.manage')->post('/payroll', ...);

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