mardi 25 octobre 2016

How to defined multiple guard and access to that it member in from laravel4.2 to Laravel5.3.19

I'm just upgrade From laravel4.2 to laravel5.3.19 now i want to access Authentication data by below method

1: Auth::employees()->attempt($data)
2: Auth::admin()->logout()
3: Auth::admin()->get()->email
.................................
Example: Auth::guard->guardName->property.

I think All of those method should be call

1:Auth::user()->id

But i don't want to correct all old method because they used a lot of in this system so i want to find the solution by keeping those method as the same. And I have configured Auth.php in Configure directory as below but it simply not work as expected.

'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admin'
        ],
        'employee' => [
            'driver' => 'session',
            'provider'  => 'employee'
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'employee'=>[
            'driver'=>'eloquent',
            'model'=>App\Models\Employee::class
        ],
        'admin' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class
        ],

    ],

Please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire