Minor change to native Model
class to fix some IDE issues
#43858
Unanswered
BrekiTomasson
asked this question in
Ideas
Replies: 3 comments 1 reply
-
Why not submit a PR to add the DocBlock? |
Beta Was this translation helpful? Give feedback.
1 reply
-
a more macro level issue is using static typing in Laravel core: #36595 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I solved mine with a custom base Model class aswell:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the biggest reason people reach for tools like the Laravel IDE Helper is because of how most IDE:s don't natively understand that Models can use Builder methods, meaning that as soon as you type that initial
::where('foo', 'bar')
you get that dreaded yellow line of "Method 'where' not found in \App\Models\Auth\User". For the longest time, I've been using a hacky workaround by simply creating my own\App\Models\Model
class that extendsIlluminate\Database\Eloquent\Model
and then adding this DocBlock to the entire class:That way, whenever I create a new model, I can extend my own
Model
class instead of Laravel'sModel
class, and my IDE understands thatBuilder
methods should be available as well. Now, as you can imagine, this fails as soon as I need to use a third party package's models, as they obviously extend Laravel's model class instead of my own, so that's got me thinking...... why isn't this simple PHP DocBlock part of Laravel's code already? I can't imagine it would break anything, and it would be a much more "native" way of solving the problem of the IDE finding your magic methods than installing a third party package that creates a separate file to trick the IDE, right?
Beta Was this translation helpful? Give feedback.
All reactions