laravel-query-builder icon indicating copy to clipboard operation
laravel-query-builder copied to clipboard

PHPStan doesn't know the return type of QueryBuilder

Open genesiscz opened this issue 7 months ago • 0 comments

Hello,

I am not sure if I am missing something but let me explain.

When I do

        $formFields = FormField::query()->where("id", $formField->id);
        $a = $formFields->firstOrFail();
        \PHPStan\dumpType($a);

        $b = QueryBuilder::for(FormField::query()->where('id', $formField->id))
            ->allowedIncludes(['formFieldSelectItems'])
            ->get();

        \PHPStan\dumpType($b);

I recieve

 45     Dumped type: App\Models\Forms\FormField                                                                                                                                                            
  51     Dumped type: Illuminate\Database\Eloquent\Collection<int, Illuminate\Database\Eloquent\Model>       

I feel like the collection should be automatically inferred or somehow working without PHPDocs, shouldn't it? I have this line in FormField:

@method static Builder<FormField>|FormField query()

Am I missing something or wasn't this thought of ?

Also, I think that the QueryBuilder should be generic in the first place, shouldn't be?

genesiscz avatar Jun 30 '24 16:06 genesiscz