我使用Laravel 5.2,我需要使用多表身份验证。 我从这个链接中读到任何人都可以通过示例解释Laravel 5.2 Multi Auth
我修改了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() 。 如何解决这个错误?
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?
最满意答案
我相信错误不是attempt方法,而是在这里:
$admin = Auth::admin();你尝试在这里运行admin方法,显然在Illuminate\Auth\SessionGuard类中没有这样的方法。
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.
更多推荐
Auth,'admin',Laravel,电脑培训,计算机培训,IT培训"/> <meta name=&quo
发布评论