skip to Main Content

I want to know how methods are declared in Laravel’s facades. For example, I want to create a user-defined function to index my login page. Firstly, I need to check whether the user is already authenticated. To do that, I will use Laravel’s Auth facade.

public function indexLogin() {

    if (Auth::check()) {
        return redirect('/mainpage');
    }

}

But, when I wanted to learn more about this method, the only thing I came across were declarations made in the PHPDoc section.

/*
*
* @method static bool check()
*
*/

For this case, I know what the method does but also want to know how it works. I believe the declarations that were made in PHPDoc sections are not enough to run methods.

I checked Laravel’s official documentation but found nothing.

2

Answers


  1. You see at the end of the methods declaration, before the class name declaration there is a PHPDoc :

    @see IlluminateAuthAuthManager
    @see IlluminateContractsAuthFactory
    @see IlluminateContractsAuthStatefulGuard
    @see IlluminateContractsAuthGuard
    

    you can check them to know how the method works.

    Login or Signup to reply.
  2. In the documentation, you can see where the methods come from as pointed out by @xenooooo.

    by digging a bit, you cas see that check() is using user()

    /**
     * Determine if the current user is authenticated.
     *
     * @return bool
     */
    public function check()
    {
        return ! is_null($this->user());
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search