0

I am trying to make separated authentication in laravel 5.2 for users and admins.

For this I have two tables - users and admins. For users, its working fine. For admins table, its not working. I am getting "These credentials do not match our records." error. I have also configured necessary information as below.

Any help is much appreciated.

config/auth.php

.....

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

    'providers' => [  
    'users' => [  
    'driver' => 'eloquent',  
    'model' => App\Models\Frontend\User::class,  
    ],  

    'admins' => [  
    'driver' => 'eloquent',  
    'model' => App\Models\Backend\Admin::class,  
    ],  
    ],

...........

app/Http/Kernel.php

.....
    protected $middlewareGroups = [  
    'web' => [  
    \App\Http\Middleware\EncryptCookies::class,  
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,  
    \Illuminate\Session\Middleware\StartSession::class,  
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,  
    \App\Http\Middleware\VerifyCsrfToken::class,  
    ],  

    'api' => [
    'throttle:60,1',
    ],

    'admin' => [  
    \App\Http\Middleware\EncryptCookies::class,  
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,  
    \Illuminate\Session\Middleware\StartSession::class,  
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,  
    \App\Http\Middleware\VerifyCsrfToken::class,  
    ]  
    ];  

    protected $routeMiddleware = [  
    'auth' => \App\Http\Middleware\Authenticate::class,  
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,  
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,  
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class  
    ];  

app/Http/routes.php

......
    Route::group(['middleware' => ['admin']], function () {  
    Route::group(['namespace' => 'Backend\Auth', 'prefix' => 'admin'], function ()     {  
    Route::get('login', 'AuthController@getLogin');  
    Route::post('login', 'AuthController@postLogin');  
    Route::get('logout', 'AuthController@getLogout');  
    });  
    });  
Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84
wilder
  • 1
  • 3
  • post your postLogin method. – ssuhat Jan 06 '16 at 06:00
  • I dont have postLogin Method on AuthController Class. It uses default functionality. Even I make one and do manual authentication it throws same error. Route::post('login', 'AuthController@postLogin'); Above route is for url only - "admin/login" – wilder Jan 06 '16 at 06:12
  • I have tried and its authenticating admin and user properly but still having problem with creating session for admin table. Working fine for user table. http://stackoverflow.com/questions/34614753/can-anyone-explain-laravel-5-2-multi-auth-with-example – imrealashu Jan 12 '16 at 16:36
  • Try this one: http://stackoverflow.com/questions/34614753/can-anyone-explain-laravel-5-2-multi-auth-with-example – Eduardo Zluhan Jan 25 '17 at 19:55

0 Answers0