phpphpstanlaravel-facade

Larastan doesn't resolve aliase of facades


I'm using larastan on a Laravel project.
When I use a facade like \Auth::check() like code below, larastan can't resolve the return type of this method.

function index()
{
  if(\Auth::check()) { // as mixed
    // ...
  }
}

I know it's resolved by adding a use operator with Illuminate\Support\Facades\Auth; and using Auth::check() instead.

use Illuminate\Support\Facades\Auth;

function index()
{
  if(Auth::check()) { // as bool
    // ...
  }
}

Is it not recommended to use alias of facades with larastan?
Let me know the best practice if there are some way to use facade alias with larastan.


PHP: 8.1
larastan: 2.9.2


Solution

  • This is solved by myself using laravel-ide-helper.

    Install it and run a command below, _ide_helper.php is generated and it solves facade definitions correctly.

    php artisan ide-helper:generate