PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

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

 January 19, 2022     laravel, mysql, php     No comments   

Issue

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.


Solution

It should be :

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

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



Answered By - Vaso Gamdelidze
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing