PHPackages                             grazulex/laravel-multipersona - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. grazulex/laravel-multipersona

ActiveLibrary[Testing &amp; Quality](/categories/testing)

grazulex/laravel-multipersona
=============================

Laravel MultiPersona is a lightweight context-layer system for Laravel users. It allows a single user to switch between different roles, accounts, or tenants dynamically, without creating multiple logins or sessions.

v1.0.0(9mo ago)96212↓50%2MITPHPPHP ^8.3CI passing

Since Aug 5Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/Grazulex/laravel-multipersona)[ Packagist](https://packagist.org/packages/grazulex/laravel-multipersona)[ Docs](https://github.com/grazulex/laravel-multipersona)[ Fund](https://paypal.me/strauven)[ GitHub Sponsors](https://github.com/Grazulex)[ RSS](/packages/grazulex-laravel-multipersona/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Laravel MultiPersona
====================

[](#laravel-multipersona)

[![Laravel MultiPersona](new_logo.png)](new_logo.png)

**Laravel MultiPersona** is a lightweight context-layer system for Laravel users.

[![Latest Version](https://camo.githubusercontent.com/5abef297e14a5451b24ee1dea7609d3c0963ebb55c584a51cad91d20bf5e7fa1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a756c65782f6c61726176656c2d6d756c7469706572736f6e612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-multipersona)[![Total Downloads](https://camo.githubusercontent.com/22123415de005345c72a6a6eba0ff5c13fb319bd5de8b6902342353933e59cc2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a756c65782f6c61726176656c2d6d756c7469706572736f6e612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-multipersona)[![License](https://camo.githubusercontent.com/ae9688f566e2ceb6048dbc6f3a1dfda1b681f18a260ccb8e77a1ac8683f611c8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6772617a756c65782f6c61726176656c2d6d756c7469706572736f6e612e7376673f7374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-multipersona/blob/main/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/27a6e023d3b886b12d55bc18773249c67cba8391eb181cd449360cb45f7e428e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6772617a756c65782f6c61726176656c2d6d756c7469706572736f6e612e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/7592d340e2de1142fa869382b819654d6a0bf7baf8e3c8aded777d652d68c01a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31322e782d6666326432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com/)[![Tests](https://camo.githubusercontent.com/b8996c980261efb58d5cc7652c4f28de7d540d6c782a1bd1afbf39599807f4bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6772617a756c65782f6c61726176656c2d6d756c7469706572736f6e612f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-multipersona/actions)[![Code Style](https://camo.githubusercontent.com/161d70e6871f808e0439b3e7a86540993ae98775540b5a2e78226000e3c419c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d70696e742d3030303030303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://github.com/laravel/pint)

---

**Laravel MultiPersona** is a lightweight context-layer system for Laravel users.
It allows a single user to switch between different **roles**, **accounts**, or **tenants** dynamically, without creating multiple logins or sessions.

---

🔍 What It Solves
----------------

[](#-what-it-solves)

- Switch between "personas" (admin ↔ client, company A ↔ company B)
- Contextual permissions and role handling
- No UI or API enforced – 100% backend, policy, and middleware-driven

📦 Installation
--------------

[](#-installation)

```
composer require grazulex/laravel-multipersona
```

🧩 Core Concepts
---------------

[](#-core-concepts)

- **Persona**: A context attached to a user (e.g. company, role, project)
- **Active Persona**: The currently selected context
- **Persona Manager**: A service to query, switch, or manipulate personas
- **Middleware**: Force or apply a persona context

✅ Quick Example
---------------

[](#-quick-example)

```
// Get current active persona
$currentPersona = persona();

// List all user personas
$userPersonas = auth()->user()->personas;

// Create a new persona
$persona = auth()->user()->createPersona([
    'name' => 'Company Admin',
    'context' => [
        'role' => 'admin',
        'company_id' => 123,
        'permissions' => ['read', 'write', 'delete']
    ]
]);

// Switch to persona
auth()->user()->switchToPersona($persona);
```

🧱 What's Provided
-----------------

[](#-whats-provided)

- **Trait**: `HasPersonas` for your `User` model
- **Middleware**: `EnsureActivePersona`, `SetPersonaFromRequest`
- **Helpers**: `persona()`, `personas($user)`
- **Events**: Complete event system for persona lifecycle
- **Service**: `PersonaManager` for programmatic access
- **Contract**: `PersonaInterface` for custom implementations

❌ What's Not Included
---------------------

[](#-whats-not-included)

- No routes or controllers
- No CLI or HTTP APIs
- No UI layer – you choose how to expose it

📚 Complete Documentation
------------------------

[](#-complete-documentation)

### Getting Started

[](#getting-started)

- [📖 Installation Guide](docs/installation-guide.md) - Complete setup instructions
- [� Usage Guide](docs/usage-guide.md) - Basic and advanced usage examples
- [⚡ Quick Start Example](examples/basic_usage.php) - Working code examples

### Core Features

[](#core-features)

- [🎭 Events Guide](docs/events-guide.md) - Event system and listeners
- [🛡️ Middleware Guide](docs/middleware-guide.md) - Route protection and context
- [🏗️ Architecture](docs/architecture.md) - System design and components

### Advanced Topics

[](#advanced-topics)

- [🎯 Advanced Patterns](docs/advanced-patterns.md) - Multi-tenant, role hierarchy, delegation
- [🌐 Frontend Integration](docs/frontend-integration.md) - Vue.js, React, Alpine.js examples
- [📋 API Reference](docs/api-reference.md) - Complete method documentation

### Use Cases

[](#use-cases)

- **Multi-tenant SaaS**: Users switch between different company contexts
- **Role-based Access**: Same user, different permissions per context
- **Agency Management**: Manage multiple client accounts
- **Marketplace Platforms**: Buyer/seller context switching
- **Enterprise Systems**: Department or project-based access

🎯 Real-World Examples
---------------------

[](#-real-world-examples)

### Multi-tenant Application

[](#multi-tenant-application)

```
// User switches between companies
$companyA = $user->createPersona([
    'name' => 'Acme Corp Admin',
    'context' => [
        'company_id' => 1,
        'role' => 'admin',
        'permissions' => ['manage_users', 'view_reports']
    ]
]);

$companyB = $user->createPersona([
    'name' => 'TechStart User',
    'context' => [
        'company_id' => 2,
        'role' => 'user',
        'permissions' => ['view_dashboard']
    ]
]);
```

### Middleware Protection

[](#middleware-protection)

```
// Protect routes requiring specific roles
Route::middleware(['auth', 'persona.required', 'role:admin'])->group(function () {
    Route::get('/admin/dashboard', [AdminController::class, 'dashboard']);
});
```

### Frontend Integration

[](#frontend-integration)

```

```

🧪 Testing
---------

[](#-testing)

The package includes comprehensive test coverage:

```
composer test
```

Current test metrics:

- **58 tests** across Unit, Feature, Integration, and Listeners
- **87% code coverage**
- **149 assertions** ensuring reliability

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Setup

[](#development-setup)

```
git clone https://github.com/grazulex/laravel-multipersona.git
cd laravel-multipersona
composer install
composer test
```

🔒 Security
----------

[](#-security)

If you discover any security vulnerabilities, please review our [Security Policy](SECURITY.md).

📄 License
---------

[](#-license)

Laravel MultiPersona is open-sourced software licensed under the [MIT license](LICENSE.md).

---

Made with ❤️ for the Laravel community

 [📖 Documentation](https://github.com/grazulex/laravel-multipersona/wiki) • [🐛 Report Issues](https://github.com/grazulex/laravel-multipersona/issues) • [💬 Discussions](https://github.com/grazulex/laravel-multipersona/discussions)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance58

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

280d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/888105bd54b6b7f7905523a16a1d08eebc2e5d39b19a4c174b5961bb4d52929b?d=identicon)[Grazulex](/maintainers/Grazulex)

---

Top Contributors

[![Grazulex](https://avatars.githubusercontent.com/u/4521546?v=4)](https://github.com/Grazulex "Grazulex (15 commits)")

---

Tags

laravelphpuser-managementmiddlewarepestlaravelContextrolesphp8tenantsPersonamultipersona

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/grazulex-laravel-multipersona/health.svg)

```
[![Health](https://phpackages.com/badges/grazulex-laravel-multipersona/health.svg)](https://phpackages.com/packages/grazulex-laravel-multipersona)
```

###  Alternatives

[grazulex/laravel-devtoolbox

Swiss-army artisan CLI for Laravel — Scan, inspect, debug, and explore every aspect of your Laravel application from the command line.

1535.4k](/packages/grazulex-laravel-devtoolbox)[christophrumpel/missing-livewire-assertions

This package adds missing livewire test assertions.

149336.0k9](/packages/christophrumpel-missing-livewire-assertions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
