PHPackages                             matthanley/laravel-polyauth - 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. matthanley/laravel-polyauth

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

matthanley/laravel-polyauth
===========================

Polymorphic Authentication for Laravel

0204PHP

Since Aug 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/matthanley/laravel-polyauth)[ Packagist](https://packagist.org/packages/matthanley/laravel-polyauth)[ RSS](/packages/matthanley-laravel-polyauth/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Polymorphic Authentication for Laravel
======================================

[](#polymorphic-authentication-for-laravel)

Allows authentication using multiple User models in Laravel 5.

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

[](#installation)

Installation is performed via Composer:

`composer require matthanley/laravel-polyauth`

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

[](#configuration)

Register the auth driver by adding the following to the `boot()` method in `app/Providers/AuthServiceProvider.php`:

```
\Auth::provider('polymorphic', function ($app) {
    return $app->make(\PolyAuth\Providers\UserProvider::class);
});
```

Update `config/auth.php` to set your auth driver to `polymorphic` and define the models with which you wish to authenticate:

```
'providers' => [
    'users' => [
        'driver' => 'polymorphic',
        'models' => [
            App\User::class,
            App\Admin::class,
        ],
    ],
],
```

Ensure your user models are using globally unique identifiers and add events to enforce globally unique emails/usernames etc. For example:

```
/**
 * Migrations
 */

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->uuid('id')->unique();
            $table->primary('id');
            /* ... */
        });
    }
}

/**
 * Models
 */

use Illuminate\Support\Facades\Auth;
use Ramsey\Uuid\Uuid;

class User extends Authenticatable
{

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            // Generate an ID
            $model->setAttribute($model->getKeyName(), Uuid::uuid1()->toString());
            // Make sure email is globally unique
            if (Auth::getProvider()->retrieveByCredentials(['email' => $model->email])) {
                throw new \Exception();
            }
        });
    }

    /* ... */
}
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/04eed5e74f9de5ef6b6e02a21112ac8dba64af91e65df5d71448144555c7728b?d=identicon)[matthanley](/maintainers/matthanley)

---

Top Contributors

[![matthanley](https://avatars.githubusercontent.com/u/3798302?v=4)](https://github.com/matthanley "matthanley (3 commits)")

### Embed Badge

![Health badge](/badges/matthanley-laravel-polyauth/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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