I noticed that my Laravel API does not return entity identifiers (the primary keys) as integers.
In Api\PostController.php::show():
function index()
{
$posts = Post::all();
return $posts;
}
Which returns something like:
[{
"id": "1",
"title": "Post one",
...
},{
"id": "2",
"title": "Post two",
...
}]
This messes up my table sorting (because IDs will be sorted as string: 1, 10, 11, 2 etc.).
Dumping the entity itselfs also shows that the id
attribute is a string.
As mentioned here the probable cause is that the MySQL driver does not return values in the appropriate type.
I'm using HHVM 3.3.1 on a Ubuntu 14.04 server. Is there any way I can use a native MySQL library (like php5-mysqlnd) for HHVM?
I could use Laravel model accessors to solve the problem. But that is more of a hack IMO.
Please help!
References:
- http://forumsarchive.laravel.io/viewtopic.php?pid=58151
- https://github.com/facebook/hhvm/issues/3619
EDIT: I have verified that it's not the ORM layer of Laravel. The PDO instance already returns IDs as strings.