jeudi 28 décembre 2017

How to use Multiple Guard in Laravel 5.5 using Tymon\JWT

I have five guards options in api config file like below.

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

    'api_admin' => [
        'driver' => 'jwt',
        'provider' => 'user_admin',
    ],
    'api_client' => [
        'driver' => 'jwt',
        'provider' => 'user_client',
    ],
    'user_carrier' => [
        'driver' => 'jwt',
        'provider' => 'user_carrier',
    ],
    'user_client' => [
        'driver' => 'jwt',
        'provider' => 'user_client',
    ]
],

So I intend to use different "guard" for different types of requests like below.

$guard = request()->get('guard'); // driver or admin
JWTAuth::guard('api_'.$guard)

This gives me this error:

"Method [guard] does not exist."

But when I use default Auth class supported by Laravel, it works fine.

Here is my working code :

$guard = request()->get('guard'); // driver or admin
Auth::guard('api_'.$guard)

How can I solve this problem ?

Any suggestion or advice would be appreciated.

Thank you in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Cj1Wi8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire