You're running into common PHPStan/Larastan issues., i.e. phpstan: Cannot call method active() on mixed.
This error means PHPStan isn't sure what type $query is inside your closure,
Illuminate\Database\Eloquent\Relations\Relation is a generic base class. PHPStan needs to know the specific relation type (e.g., HasMany, BelongsTo) to correctly infer the available methods, especially custom scopes like active().
Laravel's with() closure receives an instance of the specific relation class (e.g., Illuminate\Database\Eloquent\Relations\HasMany, Illuminate\Database\Eloquent\Relations\BelongsTo, etc.), which then proxies calls to the underlying Eloquent\Builder.