PHPackages                             chuoke/laravel-user-identify - 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. chuoke/laravel-user-identify

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

chuoke/laravel-user-identify
============================

Laravel multi identifier auth provider to thin user model/table.

v0.3.0(1y ago)020MITPHPPHP ^8.0

Since Oct 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chuoke/laravel-user-identify)[ Packagist](https://packagist.org/packages/chuoke/laravel-user-identify)[ Docs](https://github.com/chuoke/laravel-user-identify)[ GitHub Sponsors](https://github.com/:vendor_name)[ RSS](/packages/chuoke-laravel-user-identify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

Laravel multi identifier auth provider to thin your user model/table.
=====================================================================

[](#laravel-multi-identifier-auth-provider-to-thin-your-user-modeltable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca6246741fdaeda6b224da6d5ac6447382af93a611e28726b9444007b8aacb07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368756f6b652f6c61726176656c2d757365722d6964656e746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chuoke/laravel-user-identify)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2d4dfa46d79ec1ea971249e9f045f6b9983adc7ee9a96a3a80cf5565b747a377/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6368756f6b652f6c61726176656c2d757365722d6964656e746966792f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/chuoke/laravel-user-identify/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/61c0c47eba951fff335af01718be8ecc00ad1fcba0ed8d90460ed477680e7592/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6368756f6b652f6c61726176656c2d757365722d6964656e746966792f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/chuoke/laravel-user-identify/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/fd3976e0534833d67e7617ca5c1fd44e20731d7b1a3912a15befff076b5c99b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368756f6b652f6c61726176656c2d757365722d6964656e746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chuoke/laravel-user-identify)

---

Why this?
---------

[](#why-this)

> In-depth learning and understanding about Laravel by transforming its features.

Nowadays, there are many ways to log in, especially social login has become very popular. Usually we would add login identifiers to the `users` table, and while this is makes the use of this identification information and access to Laravel's existing logic simple. But this makes the `users` table very bloated, and these login identifiers are usually of little use in business logic. In order to simplify the `users` table and More convenient way to add login ways. I created this package.

With the help of this package, my `user` table is concise.

```
CREATE TABLE `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `avatar` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
)
```

The `users` table's `email`, `password`, `remember_token`, and any social login ids are converted into the identifier credentials table `user_identifiers`.

If you need to add other authentication identifier, just add one record.

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

[](#installation)

> Not fully available !!!!
>
> At present, I only use a some login method based on this package, welcome to improve it.

You can install the package via composer:

```
composer require chuoke/laravel-user-identify
```

```
php artisan vendor:publish --provider="Chuoke\UserIdentify\UserIdentifyServiceProvider"
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="user-identify-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="user-identify-config"
```

Config
------

[](#config)

This is the contents of the published config file:

In `config/user-identify.php`:

```
return [
    'idetifier_model' => Chuoke\UserIdentify\Models\UserIdentifier::class,
    'idetifier_table' => 'user_identifiers',
    'idetifier_user_key' => 'user_id',

    'user_model' => App\Models\User::class,
    'user_key' => 'id',

    'auth_provider_name' => 'user_identify',

    'actions' => [
        'user_save_from_socialite' => \Chuoke\UserIdentify\Actions\UserSaveFromSocialite::class,
    ],
];
```

Add `user_identify` guard provider to `auth.php` config file like this:

In `config/auth.php`:

```
return [

    'defaults' => [
        'guard' => env('AUTH_GUARD', 'web'),
        'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'user_identify',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'user_identify' => [
            'driver' => config('user-identify.auth_provider_name', 'user_identify'),
        ],
    ],
    // ...
];
```

Next, register auth provider:

In `AuthServiceProvider.php`:

```
use Chuoke\UserIdentify\UserIdentifyProvider;
use Illuminate\Contracts\Foundation\Application;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Auth::provider(config('user-identify.auth_provider_name'), function (Application $app, array $config) {
            return new UserIdentifyProvider(
                $app['hash'],
                config('user-identify.user_model'),
                config('user-identify.idetifier_model'),
            );
        });
    }
}
```

Usage
-----

[](#usage)

Sign in with GitHub account.

```
