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

XSkinner's avatar

decimal or integer columns are returned as strings

Hello!

Well as the title states, I'm having problem with this, since in my migration table I have:

$table->decimal('price');
$table->integer('users');
$table->integer('storage');

The returned response looks like this:

[{"animals":"5","created_at":"2018-02-20 17:54:25","emails":"92","period":"8","price":"9","sms":"72","storage":"1430""users":"6"}].

I don't know what I'm doing wrong, if I set any of the into the casts property of the model, it works, but I think it should work without casting them... doesn't it?

0 likes
3 replies
XSkinner's avatar

Thank you for answering @Cronix Well actually yeah it is... but just noticed that it only happens while testing. I'm using in memory sqlite DB as Jeff taught us in some series. So the problem is regarding SQLite now... Any idea?

Cronix's avatar
Cronix
Best Answer
Level 67

Sorry, not sure for sqlite. It's a PDO issue. Taylor said to use casts. https://github.com/laravel/framework/issues/3548

Not sure why PDO does this in the first place. It's stupid. You shouldn't have to cast things. You should get the data exactly as it's stored.

1 like

Please or to participate in this conversation.