fbpx
  • Win a Fitbit Inspire HR when you move your hosting to us. Competition ends 30 November 2019

Eloquent collections return strings instead of double / floating point numbers

You have just moved your Laravel application from one server to another. All of a sudden you get blanks where data from MySQL or Microsoft SQL should be displayed.

This worked before on the old server.

You troubleshoot using DD and then you notice that all numerics are returned as a string. On the old server, DD returns actual numerics.

The problem is between different operating systems and versions of databases. The best and quickest workaround is to use casting.

Go to your model, then do something like this:

class History extends Model
{
    protected $casts = [
        'spread' => 'double',
        'bitstamp' => 'double',
        'luno' => 'double',
        'eurozar' => 'double',
        'btcusd' => 'double',
    ];
}

Reference:

https://stackoverflow.com/questions/26974914/laravel-eloquent-integers-returned-as-strings-in-mssql

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top