plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request]: Add PHPDoc type hints for generated model relations to improve PHPStan support

Open faytecCD opened this issue 6 months ago • 2 comments

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.

faytecCD avatar Sep 10 '25 09:09 faytecCD

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.

gorbunov avatar Sep 12 '25 04:09 gorbunov

🔁 Duplicate #1124

faytecCD avatar Oct 28 '25 08:10 faytecCD