Best practice for code-completion after retrieving an Eloquent model using Model::first()
I recently read (and now I can’t find it) an article that claimed it was bad practice to use a DocBlock comment to typehint the return value of Model::first(). If I recall, the article was a code style guide used by a project.
Does anyone happen to know what article I’m talking about?
Here’s the specific thing I recall. They claimed that this was not best practice: /** @var User $user */ $user = User::first();
There was something else they did that allowed the IDE to know that $user was a User type.
Without the comment, my IDE (PhpStorm) can’t do any code-completion for my $user object. Is there something I should be doing so the IDE recognizes $user as a User besides this comment?
Thanks for any help!
Edit: I have the Laravel Idea plugin enabled, and I also use the ide-helpers plugin, but PhoStorm still doesn’t recognize the model in my example. submitted by /u/mtmo
[link] [comments]
0 comments:
Post a Comment
Thanks