[Feature Request]: Add PHPDoc type hints for generated model relations to improve PHPStan support
Feature Description
When generating model relations, it would be very helpful if PHPDoc annotations were automatically added so that static analyzers like PHPStan can better infer the relation types.
Currently, the generated relation looks like this:
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
It would be much more useful if it could be generated like this:
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
This way, PHPStan (and other static analysis tools) can properly recognize the generic relation type.
I have checked the Generate Model settings and File Templates, but did not find any configuration option that supports this. Therefore, I’d like to propose adding this as a feature.
Thank you for taking the time to share your request! We actually working on this, in recent version we added Builder generic typehints, relations support is also in the internal task tracker. This will likely will be implemented after big Model helper rework that going on right now, so right now I can't set exact version it will be done.
🔁 Duplicate #1124