Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cham11ng's avatar

Pluck id (integer) cast to string !

While plucking from a database, I get id as strings.

$alphabets = new Alphabet();
return $alphabets->pluck('name', 'id');

Output

{
    "1": "Apple",
    "2": "Ball",
    "3": "Cat"
}

Expected

{
    1: "Apple",
    2: "Ball",
    3: "Cat"
}

But, when I reverse ID and name,

return $alphabets->pluck('id', 'name');

I get id as integer.

{
    "Apple": 1,
    "Ball": 2,
    "Cat": 3
}

I'm not sure what's happening behind the scene. But how can I get ID in integer ? Actually, Old flash session doesn't set value because of 1 vs "1".

 {!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}
0 likes
4 replies
thoasty's avatar

There are no integer indexes / keys in json. What are you trying to achieve with the output?

1 like
cham11ng's avatar
 {!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}

Old flash session doesn't set value because of 1 vs "1"

cham11ng's avatar

Oh yeah! ah ha this is working so I should be waiting until merge and release.

1 like

Please or to participate in this conversation.