Larastan does not understand dynamic relation resolvers
Author: webardCreated Nov 6, 2025Updated Aug 31, 2026
Labelsenhancement
- Larastan Version: 3.8.0
- Laravel Version: 12.37.0
Description
Larastan seems to not understand relations described by resolveRelationUsing method.
Product::resolveRelationUsing('inventories',
fn (Product $productModel) => $productModel->hasMany(Inventory::class));
I have a relation in ServiceProvider, but PHPStan/Larastan detects it as undefined function:
Call to an undefined method App\Models\Product::inventories().
method.notFound When I put the relation directly in Product model, everything works fine.
Laravel code where the issue was found
In AppServiceProvider.php boot:
Product::resolveRelationUsing('inventories',
fn (Product $productModel) => $productModel->hasMany(Inventory::class));
Source: larastan/larastan