Skip to content

pluck() should infer value type from @property annotations #486

@alies-dev

Description

@alies-dev

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions