barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.09k stars 1.16k forks source link

Issues after Laravel 11.15 #1572

Open Sergiobop opened 1 month ago

Sergiobop commented 1 month ago

Versions:

Description:

Additionally to issues like https://github.com/barryvdh/laravel-ide-helper/issues/1571, Laravel 11.15 also ruined some other _ide_helper.php methods (find, findOrFail, etc)

I think is related to https://github.com/laravel/framework/pull/51851 and https://github.com/laravel/framework/pull/52037

Before 11.15:

/**
             * Find a model by its primary key or throw an exception.
             *
             * @param mixed $id
             * @param array|string $columns
             * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static|static[] 
             * @throws \Illuminate\Database\Eloquent\ModelNotFoundException<\Illuminate\Database\Eloquent\Model>
             * @static 
             */            public static function findOrFail($id, $columns = [])
            {
                                /** @var \Illuminate\Database\Eloquent\Builder $instance */
                                return $instance->findOrFail($id, $columns);
            }

After 11.15:

/**
             * Find a model by its primary key or throw an exception.
             *
             * @param mixed $id
             * @param array|string $columns
             * @return \Illuminate\Database\Eloquent\($id is (\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed>) ? \Illuminate\Database\Eloquent\Collection<int, TModel> : TModel)
             * @throws \Illuminate\Database\Eloquent\ModelNotFoundException<TModel>
             * @static 
             */            public static function findOrFail($id, $columns = [])
            {
                                /** @var \Illuminate\Database\Eloquent\Builder $instance */
                                return $instance->findOrFail($id, $columns);
            }

Now for example this is wrong: $pack = Pack::query()->findOrFail($packId);

Previous to 11.15: $pack: Pack|Pack[]|Builder|Builder[]|Collection|Model|null After 11.15: $pack: |Collection|Model|null

I don't know if we have to do something to make it work again in our end.

Thanks

joelstein commented 1 month ago

Same here.

For example, User::first() returns a User object. However, after Laravel 11.15, I get an intelephense error if I try to typehint it.

Expected type 'App\Models\User'. Found 'Illuminate\Database\Eloquent\TValue|null'.

From _ide_helper.php:

/**
 * Execute the query and get the first result.
 *
 * @param array|string $columns
 * @return \Illuminate\Database\Eloquent\TValue|null 
 * @static 
 */
public static function first($columns = [])
{
    /** @var \Illuminate\Database\Eloquent\Builder $instance */
    return $instance->first($columns);
}
max13fr commented 1 month ago

Hello,

Same for me, all models are viewed as Illuminate\Database\Eloquent\Builder instead of an instance of App\Models\MODELNAME.

Thanks in advance, Max

mengidd commented 1 month ago

Same issue here. It seems that Laravel changed the DocBlocks for the Eloquent Builder class in Laravel 11.

It now has a template tag on the class itself @template TModel of \Illuminate\Database\Eloquent\Model, and it references this template on some of the methods @return TModel.