larastan: Custom builder doc blocks are not parsed as builder generic
- Larastan Version: 0.5.2
--levelused: max
The behavior changed with PR https://github.com/nunomaduro/larastan/pull/457
Description
Calling collection methods on a result collection gives errors like Cannot call method pluck() on array<Illuminate\Database\Eloquent\Builder<mixed>>|Illuminate\Database\Eloquent\Collection.
This also happens to count(), contains(), avg(), first().
Laravel code where the issue was found
<?php
declare(strict_types=1);
namespace Tests\Unit;
use App\Models\Transaction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Topic extends Model
{
public function categories(): HasMany
{
return $this->hasMany(Category::class);
}
}
class Category extends Model
{
public function topics(): HasMany
{
return $this->hasMany(Topic::class);
}
}
$categoryIds = Transaction::query()
->groupBy('category_id')
->get(['category_id'])
->pluck('category_id');
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (10 by maintainers)
That one was generated by myself before installing the ide-helper to do it for me, my apologies. If I now create a new model called
Fooand run the ide-helper it would look like:Also, you can use
@phpstan-methodtogether with your normal docblocks.