What does Auth::guard() mean in Laravel?
習慣沉默
習慣沉默 2017-05-16 16:49:10
0
2
840

Laravel 5.3 This file vendorlaravelframeworksrcIlluminateFoundationAuthAuthenticatesUsers.php
has such a method:


   protected function guard()
    {
        return Auth::guard(); //这个语句是什么意思?返回个什么值?
    }

What does Auth::guard() mean? What value is returned?

習慣沉默
習慣沉默

reply all(2)
迷茫

According to my understanding, each Guard represents a user group.

In Laravel5.3, there is more complete support for multiple groups of users. We can have multiple groups of user systems, for example, there are one group of user systems in the frontend and one in the backend.

And what role does Guard play? Here is an example

Auth::check() is a method to determine whether the user is logged in. If you are using the default user system, then there is no problem in using it this way.

But if two groups of users are used, how to use the functions of each group of users? Auth::guard('users')->check() 就是用来判断前台用户是否登录,而 Auth::guard('admins')->check() It is used to determine whether the background user is logged in.

Generally speaking, your auth.php configuration file will be configured with a default user group, usually users. When using users in the users group, you do not need to specify guard. When using other groups of users, you need to use guard to specify which group to use. user.

Or you can look at the documentation and you may understand more.

伊谢尔伦

Guard class 的源码
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Auth/Guard.php

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template