How to properly type hint custom BaseModel so IDE recognizes child model class instead of BaseModel? #57946
Unanswered
mrvipchien
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a custom
BaseModelthat extendsIlluminate\Database\Eloquent\Model, and I want PHPStorm (and other IDEs) to correctly recognize the return type of Eloquent methods when called on child models.Current issue:
When I write:
$post = Post::query()->first();The IDE thinks
$postis an instance ofBaseModelinstead ofPost.My current code:
And my child model:
Expected:
I want the IDE to recognize that:
Post::query() returns Builder<Post>Post::first() returns Post|nullPost::find($id) returns Post|nulletc.
Beta Was this translation helpful? Give feedback.
All reactions