简体   繁体   English

Laravel 5:Auth :: guard($ this-> getGuard()) - > login($ user)之间的区别; 和auth() - > login($ user);

[英]Laravel 5: The difference between Auth::guard($this->getGuard())->login($user); and auth()->login($user);

What is the difference between: 有什么区别:

Auth::guard($this->getGuard())->login($user);

and

auth()->login($user);

? For example, in PasswordController.php we can have: 例如,在PasswordController.php中我们可以:

protected function resetPassword($user, $password)
{
    $user->password = $password;

    $user->save();

    Auth::guard($this->getGuard())->login($user);
}

or 要么

protected function resetPassword($user, $password)
{
    $user->password = $password;

    $user->save();

    auth()->login($user);
}

(in this case, we create a mutator in Users.php to bcrypt password AND NOT in resetPassword($user, $password) as it is by default) (在这种情况下,我们在Users.php中创建一个mutator来加密密码而不是在resetPassword($ user,$ password)中,因为它是默认的)

In particular, what is guard($this->getGuard()), what does it do (guard(), getGuard())? 什么是守卫($ this-> getGuard()),它做什么(guard(),getGuard())?

There is no difference, the auth function is just a helper that returns an instance of \\Illuminate\\Contracts\\Auth\\Guard . 没有区别, auth函数只是一个帮助器,它返回\\Illuminate\\Contracts\\Auth\\Guard的实例。

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM