bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.57k stars 93 forks source link

Expected type 'string|Stringable'. Found 'Illuminate\Database\Eloquent\Builder'. #2842

Closed nicolasvahidzein closed 3 months ago

nicolasvahidzein commented 3 months ago

This code works great but getting this error somehow.

Expected type 'string|Stringable'. Found 'Illuminate\Database\Eloquent\Builder'.


        //retrieve the orders that are still processing
        $ordersProcessing = Orders::query()
        ->where('order_status', '=', 'processing')->get();

        //get the current timestamp in UTC
        $ahora = Carbon::now();

        //inspect every order that is processing to see what is going on
        foreach ($ordersProcessing as $key => $order) {
            Log::channel('merlin_debug')->info('$order:');
            Log::channel('merlin_debug')->info($order);<<<<<<here shows up here

        }
bmewburn commented 3 months ago

The problem is the laravel phpdoc. query is annotated to return Illuminate\Database\Eloquent\Builder so any association the builder has with Order is lost. Using https://github.com/barryvdh/laravel-ide-helper helps somewhat as it can generate a query phpdoc method on models, but even then the types it provides are inaccurate.

Another workaround is to correct the type of $ordersProcessing with an annotation.

/** @var \Illuminate\Database\Eloquent\Collection<int, \App\Models\Order> $ordersProcessing */
$ordersProcessing = ...