[Bug]: Model-specific properties/attributes/methods won't get recognized using ::query()
Bug description
Model-specific properties/attributes/methods/relations won't get recognized anymore if you are using Model::query().
For example, this works - tasks is autocompleted:
$tasks = User::first()->tasks;
This doesn't work - tasks won't get autocompleted:
$tasks = User::query()->first()->tasks;
Model "query helpers" aka whereSomeField do get autocompleted with both methods.
Plugin version
8.2.3.241
Operating system
Linux
Steps to reproduce
- Create a model
- Add any property/attribute/relation/method/relation
- Try to make it get autocompleted "normally" as mentioned in the bug description - it'll get autocompleted
- Now try to get it autocompleted the "
::query()" way as described above - it won't get autocompleted
Relevant log output
No response
I have reported this issue once before (https://github.com/laravel-idea/plugin/issues/933), but @adelf said that he doesn't know how to fix it.
I wanted to re-open this issue and ask for it to be re-looked at, as clearly, it's not only me who likes to start queries with the query() method (https://x.com/ste_bau/status/1845536229925777916/photo/1, https://www.reddit.com/media?url=https%3A%2F%2Fpreview.redd.it%2Fghtykihdnek81.png%3Fwidth%3D1228%26format%3Dpng%26auto%3Dwebp%26s%3D20125620584fec14b2ac87edd4851c08ecd2aff4).
Can query() method not be treated similarly to select()?
Thanks
I have reported this issue once before (#933), but @adelf said that he doesn't know how to fix it. I wanted to re-open this issue and ask for it to be re-looked at, as clearly, it's not only me who likes to start queries with the
query()method (x.com/ste_bau/status/1845536229925777916/photo/1, reddit.com/media?url=https%3A%2F%2Fpreview.redd.it%2Fghtykihdnek81.png%3Fwidth%3D1228%26format%3Dpng%26auto%3Dwebp%26s%3D20125620584fec14b2ac87edd4851c08ecd2aff4). Canquery()method not be treated similarly toselect()?Thanks
Unfortunately, I don't think there is a way for us to contribute to the project, so as long as he can't figure it out, we are on our own. Or is there a way @adelf?
It's really hard to reproduce. I tried many times. It works in my PhpStorm. I understand it sounds stereotypical...
Funnily enough, I can also see a few examples that do work and some that doesn't in the same project, with seemlingly the same exact structure.
class Company extends Model
{
// ...
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// ...
}
class Application extends Model
{
// ...
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// ...
}
Company::query()->with('user')->get(); // This does NOT work
Application::query()->with('user')->get(); // This does work
Makes absolutely no sense to me why this is happening.