PHPackages                             bogardo/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. bogardo/multiauth

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

bogardo/multiauth
=================

Laravel Auth driver with support for multiple Eloquent models

v0.2.0(11y ago)536MITPHPPHP &gt;=5.4.0

Since Feb 15Pushed 11y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (4)Versions (3)Used By (0)

Bogardo\\Multiauth
==================

[](#bogardomultiauth)

[![Latest Stable Version](https://camo.githubusercontent.com/c5d012c6945eb1bbf6907b5dbd54db90a77c4cb5d941827a418ad7c82989371c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f426f676172646f2f4d756c7469617574682e7376673f7374796c653d666c6174)](https://packagist.org/packages/bogardo/multiauth)[![MIT License](https://camo.githubusercontent.com/af117b4963632449f70b5f5c504cdddc56898dc2882f938532793cb7bee45c87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f426f676172646f2f4d756c7469617574682e7376673f7374796c653d666c6174)](https://packagist.org/packages/bogardo/multiauth)[![Build Status](https://camo.githubusercontent.com/72693c634134489c373ee36f11b6a4f101c19bbf9c5db2fe7b212b00e43ae976/68747470733a2f2f7472617669732d63692e6f72672f426f676172646f2f4d756c7469617574682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Bogardo/Multiauth)[![Coverage Status](https://camo.githubusercontent.com/d38e6ca464f37a543b16bd15a39eb7864846636685b3606db898d984bf157a10/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f426f676172646f2f4d756c7469617574682f62616467652e737667)](https://coveralls.io/r/Bogardo/Multiauth)[![Packagist Downloads Total](https://camo.githubusercontent.com/800d8e4a89df203f9736757d144fe89722f37d41981be036782e86f113a9a968/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f676172646f2f6d756c7469617574682e7376673f7374796c653d666c6174)](https://packagist.org/packages/bogardo/multiauth)[![Packagist Downloads Month](https://camo.githubusercontent.com/1857754ab119cdea3298c822da599fbea67d30ec5ab7eb814ac8452f42781e49/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f626f676172646f2f6d756c7469617574682e737667)](https://packagist.org/packages/bogardo/multiauth)

Laravel authentication driver which enables you to use multiple Eloquent models for authentication.

> This package supports Laravel's password reminders by default and needs no extra configuration.

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

[](#installation)

> Currently only compatible with Laravel 4.2
> Support for Laravel 5 is on the roadmap

#### Install the package with composer

[](#install-the-package-with-composer)

`$ composer require bogardo\multiauth`

#### Add the service provider

[](#add-the-service-provider)

Add the following to your `providers` array in `app/config/app.php`

`'Bogardo\Multiauth\MultiauthServiceProvider',`

Configuration
-------------

[](#configuration)

Change the following in your `app/config/auth.php` file.

Set your driver to `multiauth`

```
'driver'    => 'multiauth'
```

Add your multiauth settings

```
'multiauth' => [

    'identifier_key' => 'email',

    'entities' => [
        [
            'type'       => 'user',
            'table'      => 'users',
            'model'      => 'User',
            'identifier' => 'username'
        ],
        [
            'type'       => 'administrator',
            'table'      => 'admins',
            'model'      => 'Admin',
            'identifier' => 'email'
        ]
    ]
]
```

Usage
-----

[](#usage)

### Prepare your models

[](#prepare-your-models)

There are 2 things that must be changed in your models

1. Add the `Bogardo\Multiauth\User\UserTrait` (replace it if it is already present)
2. Add a public `$authtype` property. The value of the property should match the `type` key defined in the `multiauth` configuration.

#### Examples

[](#examples)

##### User model

[](#user-model)

```
use Bogardo\Multiauth\User\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface
{

    use UserTrait, RemindableTrait;

    public $authtype = 'user';

}
```

##### Admin model

[](#admin-model)

```
use Bogardo\Multiauth\User\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class Admin extends Eloquent implements UserInterface, RemindableInterface
{

    use UserTrait, RemindableTrait;

    public $authtype = 'administrator';

}
```

### Validation

[](#validation)

When working with just one table for users you'd normally only check for unique emails/usernames in your users table. But when you're working with multiple tables you have to make sure that your emails/usernames are unique on all relevant tables.

This package provides a convient validation rule to do exactly that.

It will check if the supplied value (email/username) exists on any of the tables defined in the multiauth configuration. It will take note of the identifier (email/username/custom) defined in the configuration.

When using the rule without extra parameters it will make sure the supplied value does not exist in any of the tables. You'd probably use this for creating new users.

```
multiAuthUnique
```

When updating an existing user you'd want to check if the supplied value is unique **except** for the record you are updating. You can do this by supplying two parameters:

- The `type` of the user being updated
- The `id` of the user being updated

```
multiAuthUnique:user,2
```

#### Usage

[](#usage-1)

Creating new record

```
Validator::make(
    ['email' => 'email@example.com'], // data array
    ['email' => 'multiAuthUnique']    // rules array
);
```

Updating an existing Admin user with an id of 5

```
Validator::make(
    ['email' => 'email@example.com'],              // data array
    ['email' => 'multiAuthUnique:administrator,5'] // rules array
);
```

### API

[](#api)

Get the Multiauth service

```
/** @var Bogardo\Multiauth\Service $service */
$service = App::make('multiauth.service');
```

Get a collection of all registered entities The `EntityCollection` extends Laravel's `Collection`

```
$entities = $service->getEntities();

// $entities Output
object(Bogardo\Multiauth\Entity\EntityCollection)
  protected 'items' =>
    array (size=2)
	   0 =>
        object(Bogardo\Multiauth\Entity\Entity)
          public 'type' => string 'user'
          public 'table' => string 'users'
          public 'model' => string 'User'
          public 'identifier' => string 'username'
      1 =>
        object(Bogardo\Multiauth\Entity\Entity)
          public 'type' => string 'administator'
          public 'table' => string 'admins'
          public 'model' => string 'Admin'
          public 'identifier' => string 'email'

```

Get an entity by type

```
$entity = $service->getEntityByType('user');

// $entity Output
object(Bogardo\Multiauth\Entity\Entity)
  public 'type' => string 'user'
  public 'table' => string 'users'
  public 'model' => string 'User'
  public 'identifier' => string 'username'
```

---

#### Filters example implementation

[](#filters-example-implementation)

You could use this, for example, to create custom route filters for each user type.

```
/** @var Bogardo\Multiauth\Service $service */
$service = App::make('multiauth.service');
$types = $service->getEntities()->lists('type');

foreach ($types as $type) {
    Route::filter('multiauth.' . $type, function($route, $request) use ($type) {

        if (Auth::guest()) {
            // The user is not logged in.
            return Redirect::to('/');
        }

        if (Auth::user()->authtype !== $type) {
            // The user is logged in, but is not of correct type
            return Redirect::to('/');
        }
    });
}
```

This will create a route filter for every registered user type:

- user: `multiauth.user`
- administrator: `multiauth.administrator`

Which you could use to restrict access to a route which should only be accessible for a specific user type.

```
Route::get('admin', ['before' => 'multiauth.administrator', function() {
    echo 'Admins Only!!';
}]);
```

FAQ
---

[](#faq)

### - I'm unable to login using the loginUsingId and onceUsingId methods

[](#--im-unable-to-login-using-the-loginusingid-and-onceusingid-methods)

The `loginUsingId()` and `onceUsingId()` methods should be passed the **type and the id** of the user, **separated by a dot**. This deviates from the default usage, where you'd only have to pass the ID of the user.

```
Auth::loginUsingId('administrator.2');

Auth::onceUsingId('user.54')
```

---

Changelog
---------

[](#changelog)

#### v0.2.0

[](#v020)

- Added Unit Tests
- Moved Validator to it's own class
- Added Badges
- Added [Coverall](https://coveralls.io/r/Bogardo/Multiauth)

#### v0.1.0

[](#v010)

- Multiauth implementation
- Updated docs (formatting)

#### v0.0.1

[](#v001)

- Initial setup with just documentation

Todo
----

[](#todo)

- Add support for Laravel 5

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Every ~0 days

Total

2

Last Release

4110d ago

### Community

Maintainers

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

---

Top Contributors

[![Bogardo](https://avatars.githubusercontent.com/u/388557?v=4)](https://github.com/Bogardo "Bogardo (14 commits)")

---

Tags

laravelauthmulti

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)[ollieread/multiauth

Alternative auth system for Laravel

443135.6k1](/packages/ollieread-multiauth)[hesto/multi-auth

Multi Auth for Laravel

451467.6k](/packages/hesto-multi-auth)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[bmatovu/multi-auth

Laravel Multi Authentication

18325.1k](/packages/bmatovu-multi-auth)

PHPackages © 2026

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