Summary
Collection::pluck() on a typed Eloquent model always returns Collection<int, mixed>, even when the plucked column has a known type from @property annotations.
Example
/**
* @property string $notification_class
*/
class User extends Model {}
// Current: Collection<int, mixed>
// Expected: Collection<int, string>
$emails = User::query()
->select('email')
->distinct()
->get()
->pluck('email');
Problem
Because pluck() returns mixed values, downstream operations like combine() trigger InvalidTemplateParam errors since combine() expects array-key keys:
// ERROR: InvalidTemplateParam - TKey expects array-key, mixed given
$emails->combine($emails)->all();
Users must work around this with explicit @var annotations:
/** @var \Illuminate\Support\Collection<int, string> $emails */
$emails = User::query()->...->pluck('email');
Expected behavior
When pluck('column_name') is called on an Eloquent\Collection (or query builder result) where the model has @property Type $column_name, the plugin should infer the return type as Collection<int, Type> instead of Collection<int, mixed>.
This would eliminate a class of false-positive InvalidTemplateParam errors and reduce the need for manual type annotations.
Summary
Collection::pluck()on a typed Eloquent model always returnsCollection<int, mixed>, even when the plucked column has a known type from@propertyannotations.Example
Problem
Because
pluck()returnsmixedvalues, downstream operations likecombine()triggerInvalidTemplateParamerrors sincecombine()expectsarray-keykeys:Users must work around this with explicit
@varannotations:Expected behavior
When
pluck('column_name')is called on anEloquent\Collection(or query builder result) where the model has@property Type $column_name, the plugin should infer the return type asCollection<int, Type>instead ofCollection<int, mixed>.This would eliminate a class of false-positive
InvalidTemplateParamerrors and reduce the need for manual type annotations.