Php Laravel auth尝试从列表接收参数
这是我的Php Laravel auth尝试从列表接收参数,php,laravel,authentication,Php,Laravel,Authentication,这是我的AccountController课程: public function postLogin(Request $request) { if (Auth::attempt(['email' => $request ['email'], 'password' => $request ['password']]) ) { $auth = \Auth::user()->role_id; switch($auth){
AccountController
课程:
public function postLogin(Request $request) {
if (Auth::attempt(['email' => $request ['email'], 'password' => $request ['password']]) ) {
$auth = \Auth::user()->role_id;
switch($auth){
case '1': return redirect()->route('admin/index');
break;
case '2': return redirect()->route('client/home');
break;
case '3': return redirect()->route('messenger/home');
break;
}
}
}
如果特定用户的确认\u code
值为true/1,我希望我的Auth::trust
方法登录该用户
我怎么做?在Auth::trunt函数中接受特定用户确认码?只需将确认码
添加到要传递给trunt()的数组中。
方法:
Auth::attempt([
'email' => $request['email'],
'password' => $request['password'],
'confirmation_code' => true,
]);
Laravel明确指出,您可以添加任意条件。引述:
如果愿意,除了用户的电子邮件和密码之外,还可以向身份验证查询添加额外的条件。例如,我们可以验证用户是否标记为“活动”:
如果你好奇,下面是发生的事情;请注意foreach的:
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{
if (empty($credentials)) {
return;
}
// First we will add each credential element to the query as a where clause.
// Then we can execute the query and, if we found a user, return it in a
// Eloquent User "model" that will be utilized by the Guard instances.
$query = $this->createModel()->newQuery();
foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
$query->where($key, $value);
}
}
return $query->first();
}
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{
if (empty($credentials)) {
return;
}
// First we will add each credential element to the query as a where clause.
// Then we can execute the query and, if we found a user, return it in a
// Eloquent User "model" that will be utilized by the Guard instances.
$query = $this->createModel()->newQuery();
foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
$query->where($key, $value);
}
}
return $query->first();
}