search

Home  >  Q&A  >  body text

What does Auth::guard() mean in Laravel?

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?

習慣沉默習慣沉默2756 days ago824

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-16 16:51:10

    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.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 16:51:10

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

    reply
    0
  • Cancelreply