我想问你如何使用ollieread在laravel中进行多重身份验证登录?这是我在auth.php中的代码
'multi' => array(
'account' => array(
'driver' => 'eloquent',
'model' => 'users'
),
'user' => array(
'driver' => 'database',
'table' => 'admin'
)
),
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
然后,这是我的控制器
function login() {
$attributes = \Input::get();
\Auth::account()->attempt(array(
'email' => $attributes['email'],
'password' => $attributes['password'],
));
\Auth::user()->attempt(array(
'email' => $attributes['email'],
'password' => $attributes['password'],
));
\Auth::account()->check();
\Auth::user()->check();
return \View::make('superAdmin.login');
}
public function authenticateAs($type, $user) {
$this->app['auth']->$type()->setUser($user);
}
}
我不明白如何定义$attributes
。当我运行我的代码时,结果是
“缺少Illuminate \ Auth \ AuthManager :: createDriver()的参数1, 呼唤 C:\ XAMPP \ htdocs中\ laravelrental \供应商\ laravel \框架的\ src \照亮的\ Support \ Manager.php 在第88行并定义“。
那么我如何解决这个问题呢?
答案 0 :(得分:3)
在app/config/app.php
替换:
'Illuminate\Auth\AuthServiceProvider'
为:
'Ollieread\Multiauth\MultiauthServiceProvider'
答案 1 :(得分:0)
我发现在找出如何使用Ollie Read的多重身份验证解决方案时,很少有人(包括我自己)有点迷失。寻找多重身份验证解决方案我遇到了Ollie Read的https://github.com/ollieread/multiauth,然后找到https://github.com/fhferreira/auth2 我个人会推荐后者,因为这个包的设计是这样的,服务提供者将创建一个Auth2(auth2.php)的实例。因此,与Ollie Read的解决方案不同,您仍然可以使用Auth(您会注意到,在另一个解决方案中,我们不会将原始的AuthServiceProvider替换为另一个,但我们确实添加了一个新的MultiAuthServiceProvider,同时保留原始版本)没有问题。 我无法使用composer安装此软件包,但下载zip文件并将所有内容放置到位应该不会太困难。 请注意,我在代码中发现了一个拼写错误,实际上阻止了Auth2的工作。在第51行的Collection.php中,应该替换
$providers = $this->config->get('auth2::auth2');
通过
$providers = $this->config->get('auth2.auth2');
假设您的配置文件在config / auth2.php中,并且您需要针对两个不同的表/模型进行身份验证,这是您的配置文件config / auth2.php应该是什么样子
return array(
// example
'auth2' => array (
'user' => array(
'driver' => 'eloquent',
'model' => 'User',
'table' => 'users'
),
'admin' => array(
'driver' => 'eloquent',
'model' => 'Admin',
'table' => 'admins'
)
)
);
现在正如我所提到的,Auth仍允许我们对默认的User模型进行身份验证。因此,实际上可以为用户使用Auth,对管理员使用Auth2,在这种情况下,配置文件将是
返回数组(
// example
'auth2' => array (
'admin' => array(
'driver' => 'eloquent',
'model' => 'Admin',
'table' => 'admins'
)
)
);
你可以使用php artisan tinker测试一切正常。进入修补程序shell后,只需输入
即可查询配置文件Config::get('auth2')
或
Config::get('auth2.name')
查看配置文件为定义的特定名称(用户,管理员)提供的不同身份验证选项。等等,以便在数组的较低级别中选择。
希望有所帮助。