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.
CodePudding user response:
You see at the end of the methods declaration, before the class name declaration there is a PHPDoc :
@see \Illuminate\Auth\AuthManager
@see \Illuminate\Contracts\Auth\Factory
@see \Illuminate\Contracts\Auth\StatefulGuard
@see \Illuminate\Contracts\Auth\Guard
you can check them to know how the method works.
CodePudding user response:
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());
}