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',



Share this article

Leave a Reply

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

Scroll to Top