有什么区别:
Auth::guard($this->getGuard())->login($user);
和
auth()->login($user);
?例如,在PasswordController.php中我们可以:
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 中创建一个mutator来加密密码而不是 resetPassword($ user,$ password),因为它是默认的)
特别是什么是后卫($ this-> getGuard()),它做了什么(guard(),getGuard())?
答案 0 :(得分:3)
没有区别,auth
函数只是一个返回\Illuminate\Contracts\Auth\Guard
实例的帮助器。
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php