Stefano Martini
Stefano Martini

Reputation: 455

Decimal are converted to String in Laravel, cast is not working

I have a problem changing data type column in my table, from double to decimal each (6,2).

Olso trying to $cast the variable to float, I've tried to cast olso as decimal, but nothing change, nothing change:

 protected $cast = [
    'temperature' => 'float'
];

if I dd $this in my resource I got this:

enter image description here

The data back to be a number only if I rollback the data column type to double in mysql.

I've read about some problem in PDO driver, with myslq 5.2, but mine is 5.1.1

I've tried to print data without passing trough resource layer, but number are always served like string.

Upvotes: 0

Views: 1138

Answers (1)

Vaso Gamdelidze
Vaso Gamdelidze

Reputation: 179

It should be :

 protected $casts = [
    'temperature' => 'float'
];

Now you have typing mistake it should be $casts in plural except $cast

Upvotes: 1

Related Questions