PHP code example of chuoke / laravel-user-identify

1. Go to this page and download the library: Download chuoke/laravel-user-identify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chuoke / laravel-user-identify example snippets


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,
    ],
];

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'),
        ],
    ],
    // ...
];



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'),
            );
        });
    }
}



namespace App\Web\Controllers\Auth;

use Illuminate\Http\Request;
use App\Web\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

class GithubController extends Controller
{
    public function redirect(Request $request)
    {
        return Socialite::driver('github')->redirect();
    }

    public function callback(Request $request)
    {
        /** @var \Laravel\Socialite\AbstractUser $githubUser */
        $githubUser = Socialite::driver('github')->user();

        $githubUser['socialite_type'] = 'github';

        $successful = Auth::attempt([
            'identifier' => $githubUser,
        ], true);

        if ($successful) {
            return redirect('/dashboard');
        }

        return redirect('/login');
    }
}
bash
php artisan vendor:publish --provider="Chuoke\UserIdentify\UserIdentifyServiceProvider"
bash
php artisan vendor:publish --tag="user-identify-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="user-identify-config"