PHPackages                             vantezzen/laravel-account-portal - 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. [Admin Panels](/categories/admin)
4. /
5. vantezzen/laravel-account-portal

AbandonedArchivedLibrary[Admin Panels](/categories/admin)

vantezzen/laravel-account-portal
================================

Quickly switch into user accounts of your Laravel app

1.1.0(3y ago)05MITPHPPHP ^8.1

Since Jun 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/vantezzen/laravel-account-portal)[ Packagist](https://packagist.org/packages/vantezzen/laravel-account-portal)[ Docs](https://github.com/vantezzen/laravel-account-portal)[ RSS](/packages/vantezzen-laravel-account-portal/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (4)Used By (0)

Laravel Account Portal
======================

[](#laravel-account-portal)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a46b4c5e1ef0b437ac923d67d6c38fe6de5cf758e81c124d5036fb32adac443f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616e74657a7a656e2f6c61726176656c2d6163636f756e742d706f7274616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vantezzen/laravel-account-portal)[![GitHub Tests Action Status](https://camo.githubusercontent.com/f218d62c1f06801ccc6c187b6b6cf979822a573fe0571bfa8e147a997815baa2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e74657a7a656e2f6c61726176656c2d6163636f756e742d706f7274616c2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/vantezzen/laravel-account-portal/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a3de91496f18044a4e4d2fd2684af5e4b438862eb0147636959604348e592a18/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e74657a7a656e2f6c61726176656c2d6163636f756e742d706f7274616c2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/vantezzen/laravel-account-portal/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3fa6227df6b32ff00f7a8ae9f95c3ba464e7eb7744438786b7483897baafe0c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76616e74657a7a656e2f6c61726176656c2d6163636f756e742d706f7274616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vantezzen/laravel-account-portal)

> 🌌 Quickly switch into user accounts of your Laravel app for debugging, testing etc.

This package allows your admin or support staff to easily log into any user account to view your app with their data.

Under the hood, this package simply logs you into the portal user account, saving the original account info in the session to allow you to switch back.

About
-----

[](#about)

When building systems I noticed that we build the same functionality into almost all of our products:

We create a simple page, a button or API where support staff or developers can enter an email of a user or search though a list of users and log in to our app using that user's account. In some other apps I've also seen similar functionality or even worse just a "master password" that can be input as the password to log into every account without further verification.

This functionality is useful when users complain about something not working or have questions about data they created in their account so that we can view the app exactly the way they would.

In different projects this functionality might have different names - account portal, guest view, user view, support view, direct access, support login etc. - but they mostly work the same.

This package tries to be as unopinionated as possible: It doesn't define a fixed API, pre-build dashboard or makes assumptions about your user models. Instead, this package tries to provide an abstracted API for working with authenticatable classes and user sessions. Everything else - an API, interface or buttons in your frontend - can be added by you based on your apps needs.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require vantezzen/laravel-account-portal
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-account-portal-config"
```

Defining Gate
-------------

[](#defining-gate)

This package requires you to define the Gate "use-account-portal" in order to protect the portal functionality from unauthorized use.

For example, you might add such a Gate definition to your AppServiceProvider:

```
Gate::define("use-account-portal", function (User $currentUser, ?User $portalUser = null) {
    return $currentUser->isAdmin();
});
```

Your gate should determine, if the user `$currentUser` is authorized to open a portal into the account of `$portalUser`though please note that `$portalUser` might be `null` if checking that the current user is allowed to use the feature at all.

Usage
-----

[](#usage)

This package only provides a class to easily open and close account portals - you probably need to create an API controller or similar to suit the needs of your app.

### Get instance

[](#get-instance)

To control the portal, you will need an instance of the "Vantezzen\\LaravelAccountPortal\\LaravelAccountPortal" class. You can use Laravel's dependency injection or create the class manually:

```
// Use Laravel's dependency injection
class MyController extends Controller {
    public function index(Vantezzen\LaravelAccountPortal\LaravelAccountPortal $laravelAccountPortal) {
        // ...
    }
}

// ...or...

// Create manually
$laravelAccountPortal = new Vantezzen\LaravelAccountPortal\LaravelAccountPortal();
```

### Session Storage

[](#session-storage)

This package uses the current session to store information about the portal but you might choose to implement your own way of storing this information.

For this, the package uses the `PortalStorage` interface that defines the functions needed for the package.

By default, you'll simply wrap the Laravel session into a `SessionPortalStorage`:

```
use \Vantezzen\LaravelAccountPortal\PortalStorage\SessionPortalStorage;

class MyController extends Controller {
    public function index(Request $request) {
        $storage = new SessionPortalStorage($request->session());
    }
}
```

### Open portal

[](#open-portal)

To open a portal into an account, simply call the `openPortal` method:

```
class MyController extends Controller {
    // Example for a route like "/account-portal/open/{portalUserId}"
    public function openPortal(Request $request, string $portalUserId, LaravelAccountPortal $laravelAccountPortal) {
        $storage = new SessionPortalStorage($request->session());

        $laravelAccountPortal->openPortal(
            // Current session object used to store the portal information
            $storage,
            // Current user that wants to open the portal
            $request->user(),
            // User the current user wants to portal into
            User::find($portalUserId)
        );
    }
}
```

Please note that this will internally automatically check your defined gate and throw a "AccountPortalNotAllowedForUserException" if your gate denies the request.

### Close portal

[](#close-portal)

To close the portal, simply call `closePortal` with the current session

```
class MyController extends Controller {
    public function closePortal(Request $request, LaravelAccountPortal $laravelAccountPortal) {
        $storage = new SessionPortalStorage($request->session());

        $laravelAccountPortal->closePortal(
            // Current session object used to store the portal information
            $storage,

            // Get the authenticatable model instance by id
            fn($id) => User::find($id)
        );
    }
}
```

The second argument should be a `callable` that returns the model of a user by its ID. Internally, this package only stores the ID of the original user that opened the portal to get back to the account once the portal is closed. To stay unopinionated about your user modelling, you need to provide this callback to lookup the model by this saved ID.

Please note that this will throw a "NotInAccountPortalException" if the session doesn't currently have an active portal.

### Portal status

[](#portal-status)

To check the current status of the portal, you can use the helper methods `isInPortal` and `canUsePortal`:

```
$storage = new SessionPortalStorage($request->session());

// True if the session has information about being in a portal
$isInPortal = $laravelAccountPortal->isInPortal($storage);

// True if a portal can be opened into the portal user
// Please note that "$portalUser" might be left as null to check generally
$canUsePortal = $laravelAccountPortal->canUsePortal($storage, $portalUser);
```

Based on these parameters, you might choose to display an "Open account portal", "Close account portal" button or no button in your frontend.

### Multi-level portal

[](#multi-level-portal)

Please note that due to security and complexity reasons, users cannot open a portal while already in a portal.

If a user is currently in a portal, `canUsePortal` will always return `false`, making it impossible to open further portals.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Bennett](https://github.com/vantezzen)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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

Every ~0 days

Total

3

Last Release

1436d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10333196?v=4)[Bennett](/maintainers/vantezzen)[@vantezzen](https://github.com/vantezzen)

---

Top Contributors

[![vantezzen](https://avatars.githubusercontent.com/u/10333196?v=4)](https://github.com/vantezzen "vantezzen (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

account-managementlaravellaravel-packagephplaraveladminaccountvantezzenlaravel-account-portal

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vantezzen-laravel-account-portal/health.svg)

```
[![Health](https://phpackages.com/badges/vantezzen-laravel-account-portal/health.svg)](https://phpackages.com/packages/vantezzen-laravel-account-portal)
```

###  Alternatives

[guava/filament-knowledge-base

A filament plugin that adds a knowledge base and help to your filament panel(s).

206120.5k1](/packages/guava-filament-knowledge-base)[ralphjsmit/laravel-filament-seo

A package to combine the power of Laravel SEO and Filament Admin.

15398.7k10](/packages/ralphjsmit-laravel-filament-seo)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[geo-sot/filament-env-editor

Access .env file though Filament admin panel

2432.3k1](/packages/geo-sot-filament-env-editor)[caresome/filament-neobrutalism-theme

A neobrutalism theme for FilamentPHP admin panels

303.2k](/packages/caresome-filament-neobrutalism-theme)[andreia/filament-ui-switcher

Add a modal with options to switch between different UI layouts and styles (colors, fonts, font sizes).

233.8k](/packages/andreia-filament-ui-switcher)

PHPackages © 2026

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