Closed bbprojectnet closed 7 months ago
Yes, it's a new missing feature in ide-helper... the code is located in: https://github.com/barryvdh/laravel-ide-helper/blob/dda200fd34d2b9151bd6d9ddecaeb421978d6b99/src/Console/ModelsCommand.php#L570 but currently I don't have time to fix it.
The problem should already be fixed with this commit https://github.com/barryvdh/laravel-ide-helper/commit/39885645b91b0266290fce03bbfd155a67bb2e27. But since then there was no release.
New release was made -> closing
Hey, thanks for fixing this bug. I have one remaining question though. Suppose an attribute returns a collection of Post objects, how should I type hint it?
protected function filteredPosts(): Attribute
{
return Attribute::make(
/**
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\Post>
*/
get: function (): {
return $this->post->where('post_online');
}
);
}
I'd like to ensure the correct typing for this scenario. Thanks in advance for your assistance!
Looks correct to me; does it work or give you any trouble?
it's being inferred as @mixed.
@mfn @Derhelios66 Just to confirm on @marc31 answer, the mixed
type is the only inferred type for the new accessor/mutators even if we docblock the attribute with a generic type like @marc31 did
Versions:
Description:
Only
public
and type casted get/set methods attributes are detected.But, according to https://laravel.com/docs/9.x/eloquent-mutators mutator method should be
protected
.Also, it would be nice if ide helper supported the generic attribute declaration, like that:
if the get/set methods do not have a return type specified.