php - Resolve Laravel Auth Authenticatable to User model to address static analysis issues

one text

Solution:

Eventually, this is how we worked around the problem. We added a type-hint for Larastan, so it can infer that $user has this HasRolesContract trait which provides hasPermissionTo().

  public function index()
  {
        /** @var \App\Traits\HasRolesContract */
        $user = \Auth::user();

        if ($user->hasPermissionTo('Management:View Users')) {

Hopefully this helps someone else!

(Thanks for the nudge, @djjavo)

Source