【问题标题】:Laravel 5.2 Multi Table Authentication ErrorException in AuthManager.phpLaravel 5.2 AuthManager.php 中的多表身份验证ErrorException
【发布时间】:2016-07-20 08:51:00
【问题描述】:

我使用 Laravel 5.2,我需要使用多表身份验证。我从这个链接阅读Can anyone explain Laravel 5.2 Multi Auth with example

我修改了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,
    ],
], 

这里是登录控制器的一部分(post方法)

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

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

但我得到了这个错误

AuthManager.php 第 288 行中的 ErrorException:call_user_func_array() 期望参数 1 是一个有效的回调,类 'Illuminate\Auth\SessionGuard' 没有方法 'admin'

看起来错误出现在Auth::attempt()。如何解决这个错误?

【问题讨论】:

    标签: laravel authentication laravel-5.2


    【解决方案1】:

    我相信错误不在attempt 方法中,而是在这里:

     $admin = Auth::admin();
    

    你尝试在这里运行admin 方法,显然Illuminate\Auth\SessionGuard 类中没有这样的方法。

    【讨论】:

      猜你喜欢
      • 2016-08-05
      • 1970-01-01
      • 2016-05-10
      • 2016-07-09
      • 2017-02-26
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      相关资源
      最近更新 更多