3

I'm building a CMS that uses Laravel as a RESTful API and React (+ redux) as a frontend. (I've isolated the problem to be separate from the frontend)

The CMS handles multiple sites with multiple pages. When the user adds a new page, it sends the new site data: a page title, and the ID of the parent site. (i.e. 'new-page', '15')

After the API successfully saves the data, it returns the new instance fresh from the database - the page title, the parent site ID, and the new page ID (primary key) that has it has been assigned by the database.

But, for some reason that I cannot figure out, on the production server, the site_id is being returned as a string, and not an integer. (This caused a headache which I can solve with parseInt(), but I'd like to know what's up).

The code running on each is identical. I've confirmed on both that the site_id column in the database is set to int(10) unsigned. A call to the API that returns a site and all of its associated pages gives me these results (note the site_id property on each):

Development Development

Production enter image description here

Slight differences between the two environments:

PHP

php --version
 (development) PHP 5.6.24
 (production)  PHP 5.6.21

and

MySQL

select version()
  (development) 5.7.13
  (production)  5.6.25-73.1

Both are using Laravel 5.2.39.

Why would a value that is defined in the database as an INT be returned as a string across these two environments?

Update:

mysqlnd is installed on both my local and production environment.

Good Idea
  • 2,481
  • 3
  • 18
  • 25
  • 2
    Possible duplicate of http://stackoverflow.com/questions/38819501/how-to-get-laravel-query-builder-result-as-integer – Zayn Ali Aug 08 '16 at 07:07
  • 3
    Possible duplicate of [find() on model gives id as string in one environment and int in other](http://stackoverflow.com/questions/38034996/find-on-model-gives-id-as-string-in-one-environment-and-int-in-other) – trajchevska Aug 08 '16 at 07:23
  • @ZaynAli @trajchevska it looks like this isn't the same problem, `mysqlnd` is installed on both environments. From reading those questions, it sounds like *all* ints are being returned as strings - in my case, other fields (such as the `id`) are being returned correctly – Good Idea Aug 08 '16 at 19:39
  • I have the same issue since I updated PHP on the server. Maybe something in the config of PHP. – Swimburger Aug 08 '16 at 19:56

0 Answers0