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);

查看:500
本文介绍了Laravel 5:Auth :: guard($ this-> getGuard())-> login($ user)之间的区别;和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-> getGuard())-> login($ user)之间的区别;和auth()-> login($ user);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆