larastan: `FormRequest::user()`always returns the model of default guard

  • Larastan Version: 2.1.4
  • --level used: 9
  • Pull request with failing test:

Description

It seems like FormRequest::user() method is stated to return the model of default guard, even though multiple guards defined in the config/auth.php.

Providing the name of the (non-default) guard with the method argument won’t help; the method is still predicted to return the default.

Laravel code where the issue was found

Let’s say the default guard is default_user and model is \App\Models\DefaultUser.

class ExampleRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() instanceof \App\Models\AnotherUser;
        // or return $this->user('another_user') instanceof \App\Models\AnotherUser;
    }
}

It gives me the following error:

Instanceof between App\Models\DefaultUser|null and App\Models\AnotherUser will always evaluate to false.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

@canvural Could you revisit this issue?

Hey @canvural, have you seen the example above? If you need anything else to fix the problem, please let me know so I can set it up for you.