laravel-ide-helper
laravel-ide-helper copied to clipboard
Eloquent whereIn returns Eloquent\Builder not Query\Builder
Versions:
- ide-helper Version: 2.8.2
- Laravel Version: 8.18.1
- PHP Version: 8.0.0
Description:
The generated whereIn method for the Eloquent mixin has \Illuminate\Database\Query\Builder for the return object. When actually using the whereIn method on a model it actually returns \Illuminate\Database\Eloquent\Builder. I think the auto generated doc block should be changed to have the typehint of Eloquent builder instead.
Steps To Reproduce:
class Contact extends Model {}
class User extends Model
{
public function groupContacts(): Contact|\Illuminate\Database\Query\Builder
{
return Contact::whereIn('user_id', [1, 2, 3]);
}
}
Now running this will produce an error (generate the models helper first with php artisan ide-helper:models):
$group_builder = User::first()->groupContacts();
// TypeError: App\Models\User::groupContacts(): Return value must be of type App\Models\Contact|Illuminate\Database\Query\Builder, Illuminate\Database\Eloquent\Builder returned
whereIn isn't the only "affected" one, I mean I can see the same with whereNull and probably lots of others 🤷♀️
Yea - I hadn't tested the other ones so wasn't sure what to post here but figured they could all be annotating the wrong return type.
I'm having the same problem, but I experienced it through FooModel::whereIn()->get() returning Illuminate\Support\Collection instead of Illuminate\Database\Eloquent\Collection which should be returned from Illuminate\Database\Eloquent\Builder::get().
I guess while not extra helpfull me too