Laravel 5:Auth :: guard($ this-& gtgetGuard())-> login($ user)之间的区别;和auth()-& gtinlogin($ user); [英] Laravel 5: The difference between Auth::guard($this->getGuard())->login($user); and auth()->login($user);
问题描述
有什么区别:
Auth::guard($this->getGuard())->login($user);
和
auth()->login($user);
?例如,在PasswordController.php中,我们可以拥有:
? For example, in PasswordController.php we can have:
protected function resetPassword($user, $password)
{
$user->password = $password;
$user->save();
Auth::guard($this->getGuard())->login($user);
}
或
protected function resetPassword($user, $password)
{
$user->password = $password;
$user->save();
auth()->login($user);
}
(在这种情况下,我们在 Users.php 中创建一个变种器来加密密码,而不是在 resetPassword($ user,$ password)中而不是默认设置)
(in this case, we create a mutator in Users.php to bcrypt password AND NOT in resetPassword($user, $password) as it is by default)
特别是,guard($ this-> getGuard())是什么,它有什么作用(guard(),getGuard())?
In particular, what is guard($this->getGuard()), what does it do (guard(), getGuard())?
推荐答案
没有什么区别, auth
函数只是一个帮助程序,它返回 \ Illuminate \ Contracts \ Auth的实例\ Guard
.
There is no difference, the auth
function is just a helper that returns an instance of \Illuminate\Contracts\Auth\Guard
.
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php
这篇关于Laravel 5:Auth :: guard($ this-& gtgetGuard())-> login($ user)之间的区别;和auth()-& gtinlogin($ user);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!