PHPackages                             esalazarv/multiauth - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. esalazarv/multiauth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

esalazarv/multiauth
===================

Multiple auth driver for Laravel 5

v5.0.2(10y ago)91.8k1[1 PRs](https://github.com/esalazarv/multiauth/pulls)MITPHPPHP &gt;=5.4.0

Since Mar 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/esalazarv/multiauth)[ Packagist](https://packagist.org/packages/esalazarv/multiauth)[ RSS](/packages/esalazarv-multiauth/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Multi Auth
==================

[](#laravel-multi-auth)

- **Laravel**: 5.1.11
- **Author**: Eduardo Salazar
- **Author Homepage**:
- **Author**: Ramon Ackermann
- **Author Homepage**:
- **Author**: Ollie Read
- **Author Homepage**:

For Laravel 5.1.0 version, see Branch For Laravel 4.2 version, see

---

**IMPORTANT: Laravel 5.1**Default AuthController with its traits

```
\Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers

```

more specifically

```
Illuminate\Foundation\Auth\AuthenticatesUsers::postLogin()

```

---

This package is not a replacement for laravels default Auth library, but instead something that sits between your code and the library.

Think of it as a factory class for Auth. Now, instead of having a single table/model to authenticate users against, you can now have multiple, and unlike the previous version of this package, you have access to all functions, and can even use a different driver for each user type.

On top of that, you can use multiple authentication types, simultaneously, so you can be logged in as a user, a master account and an admin, without conflicts!

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

[](#installation)

Firstly you want to include this package in your composer.json file.

```
    "require": {
    		"esalazarv/multiauth" : "5.0.*"
    }
```

Now you'll want to update or install via composer.

```
composer update

```

Next you open up app/config/app.php and replace the 'Illuminate\\Auth\\AuthServiceProvider', with

```
    'Ollieread\Multiauth\MultiauthServiceProvider',
```

and 'Illuminate\\Auth\\Passwords\\PasswordResetServiceProvider' with

```
	'Ollieread\Multiauth\Passwords\PasswordResetServiceProvider',
```

**NOTE** It is very important that you replace the default service providers.

Remove the original database migration for password\_resets.

\##Configuration##

is pretty easy too, take config/auth.php with its default values:

```
    return [

		'driver' => 'eloquent',

		'model' => 'App\User',

		'table' => 'users',

		'password' => [
        		'email' => 'emails.password',
        		'table' => 'password_resets',
        		'expire' => 60,
        	],

	];
```

Now remove the first three options (driver, model and table) and replace as follows (Custom authentication drivers now work):

```
    return [

		'multi'	=> [
			'admin' => [
				'driver' => 'eloquent',
				'model'	=> 'App\Admin',
			],
			'client' => [
				'driver' => 'database',
				'table' => 'clients',
				'email' => 'client.emails.password',
			],
			'other' => [
				'driver' => 'customDriver',
				'model'	=> 'App\Other',
			],
		],

		'password' => [
        		'email' => 'emails.password',
        		'table' => 'password_resets',
        		'expire' => 60,
        	],

	];
```

This is an example configuration. Note that you will have to create Models and migrations for each type of user. Use App\\User.php and 2014\_10\_12\_000000\_create\_users\_table.php as an example.

If you wish to use a reminders email view per usertype, simply add an email option to the type, as shown in the above example.

To generate the reminders table you will need to run the following command.

```
php artisan multiauth:resets-table

```

Likewise, if you want to clear all reminders, you have to run the following command.

```
php artisan multiauth:clear-resets

```

You will also need to change the existing default Laravel 5 files to accommodate multiple auth and password types. Do as described in this gist:

Usage
-----

[](#usage)

Everything is done the exact same way as the original library, the one exception being that all method calls are prefixed with the key (account or user in the above examples) as a method itself.

```
    Auth::admin()->attempt(array(
    	'email'		=> $attributes['email'],
    	'password'	=> $attributes['password'],
    ));
    Auth::client()->attempt(array(
    	'email'		=> $attributes['email'],
    	'password'	=> $attributes['password'],
    ));
    Auth::admin()->check();
    Auth::client()->check();
```

I found that have to call the user() method on a user type called user() looked messy, so I have added in a nice get method to wrap around it.

```
	Auth::admin()->get();
```

But if you prefer, you can specify which type of user you will use to use method `uses('YourUserType')`, once this is done you can access the current user as the original Auth Facade , as easy as `Auth::user()`.

This method sets 'admin' as the current user with which to work.

```
	/** You can switch users as needed **/
	Auth::uses('admin');
```

Note: By default current user is the first in the config array.

You can now access the user just as you would with the original Facade Auth.

```
	/** Accessing the user using the 'user()' (original method) **/
	if(Auth::user()->check()){
		//
	}

	/** Accessing the user using the 'get()' (additional method)  **/
	if(Auth::get()->check()){
		//
	}
```

or using the descriptive methods that existed.

```
	if(Auth::admin()->user()->check()){
		//
	}

	if(Auth::admin()->get()->check()){
		//
	}
```

In the instance where you have a user type that can impersonate another user type, example being an admin impersonating a user to recreate or check something, I added in an impersonate() method which simply wraps loginUsingId() on the request user type.

```
	Auth::impersonate('client', 1, true);
```

or

```
	Auth::admin()->impersonate('client', 1, true);
```

The first argument is the user type, the second is the id of said user, and the third is whether or not to remember the user, which will default to false, so can be left out more often than not.

And so on and so forth.

Note: The method 'impersonate()' returns and sets the new user as the current user.

You can Know if an user is impersonated

```
	/** @return boolean **/
	if(Auth::isImpersonated()){
		//
	}
```

or

You may know the key name impersonator of current user

```
	/** @return string | null **/
	Auth::getImpersonatorName();
```

or specifying

```
	/** @return string | null **/
	Auth::client()->getImpersonatorName();
```

There we go, done! Enjoy yourselves.

Testing
-------

[](#testing)

Laravel integration/controller testing implements `$this->be($user)` to the base TestCase class. The implementation of #be() does not work correctly with Multiauth. To get around this, implement your own version of #be() as follows:

```
    public function authenticateAs($type, $user) {
      $this->app['auth']->$type()->setUser($user);
    }
```

### License

[](#license)

This package inherits the licensing of its parent framework, Laravel, and as such is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 56.6% 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 ~21 days

Recently: every ~33 days

Total

11

Last Release

3856d ago

Major Versions

v4.1.1 → v5.0.12015-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa00f6d74efa460265419e18d67496bca4b9b662c98de18bf21c3503c1cebee7?d=identicon)[esalazarv](/maintainers/esalazarv)

---

Top Contributors

[![sboo](https://avatars.githubusercontent.com/u/3823326?v=4)](https://github.com/sboo "sboo (60 commits)")[![ollieread](https://avatars.githubusercontent.com/u/469515?v=4)](https://github.com/ollieread "ollieread (35 commits)")[![esalazarv](https://avatars.githubusercontent.com/u/13573585?v=4)](https://github.com/esalazarv "esalazarv (4 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![tylerjohnst](https://avatars.githubusercontent.com/u/193916?v=4)](https://github.com/tylerjohnst "tylerjohnst (1 commits)")[![sahibalejandro](https://avatars.githubusercontent.com/u/985268?v=4)](https://github.com/sahibalejandro "sahibalejandro (1 commits)")[![shivergard](https://avatars.githubusercontent.com/u/1783151?v=4)](https://github.com/shivergard "shivergard (1 commits)")[![AliMalikTTX](https://avatars.githubusercontent.com/u/106072896?v=4)](https://github.com/AliMalikTTX "AliMalikTTX (1 commits)")

---

Tags

laravelauthlaravel 5multi

### Embed Badge

![Health badge](/badges/esalazarv-multiauth/health.svg)

```
[![Health](https://phpackages.com/badges/esalazarv-multiauth/health.svg)](https://phpackages.com/packages/esalazarv-multiauth)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[ollieread/multiauth

Alternative auth system for Laravel

443135.6k1](/packages/ollieread-multiauth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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