ide-helper:models writes Builder<static>|Model return types, which Larastan 3.12 now treats as real

Author: ItsReddiCreated Sep 25, 2026Updated Sep 29, 2026
Labelsbug

Versions:

  • barryvdh/laravel-ide-helper 3.7.0 (default config)
  • larastan 3.12.2, phpstan 2.2.14
  • Laravel 13.32, PHP 8.5

Description:

ide-helper:models annotates builder-returning methods with a union of the builder and the model:

php
/**
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Foo newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Foo newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Foo query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Foo active()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Foo whereName($value)
 */
class Foo extends Model {}

None of these methods can return Foo. They always return a builder.

Until Larastan 3.10, Larastan's return type extensions took precedence over these docblocks, so the union never reached PHPStan's analysis. Since 3.12, Larastan resolves these methods through stubs, and the model docblock now wins.

Method X::population() should return Builder<Foo> but returns Foo|Builder<Foo>. Anonymous function should return Builder<Foo> but returns Foo|Builder<Foo>.

The Larastan maintainers consider the docblock wrong and prefer a fix on the ide-helper side: larastan/larastan#2554, larastan/larastan#2555 (comments).

Source: barryvdh/laravel-ide-helper