0

I use Laravel 5.2 and I need to use multi table authentication. I read from this link Can anyone explain Laravel 5.2 Multi Auth with example

I modified config/auth.php

'guards' => [
    'user' =>[
        'driver' => 'session',
        'provider' => 'user',
    ],
    'admin' => [
        'driver' => 'session',
        'provider' => 'admin',
    ],
],  

//User Providers
'providers' => [
    'user' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
    'admin' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ]
],  

//Resetting Password  
'passwords' => [
    'user' => [
        'provider' => 'user',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
    'admin' => [
        'provider' => 'admin',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
], 

Here is part of the controller for login (post method)

$admindata = array(
    'email'     => Input::get('email'),
    'password'  => Input::get('password')
);

if (Auth::attempt($admindata)) {
    echo 'SUCCESS!';
} else {
    $admin = Auth::admin();
    return Redirect::to('/b');
}

But I got this error

ErrorException in AuthManager.php line 288: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\SessionGuard' does not have a method 'admin'

It looks like the error is on Auth::attempt(). How to solve this error?

Community
  • 1
  • 1
OrgGila
  • 333
  • 2
  • 4
  • 9

1 Answers1

0

I believe the error is not in attempt method but here:

 $admin = Auth::admin();

You try to run here admin method and obviously there is no such method in Illuminate\Auth\SessionGuard class.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291