[英]id attribute in eloquent collection changes when converting to an array
I have a database with uuid's as the id column. 我有一个数据库,其中uuid为id列。 I do a query using eloquent and it returns the correct information.
我用雄辩的方法进行查询,它返回正确的信息。 I have attached an image below because its a big object to write.
我在下面附加了一张图片,因为它是一个很大的对象。
So theres 2 items in this collection, they follow the same format but as you can see the first item has the id field which is the correct uuid. 因此,此集合中有2个项目,它们遵循相同的格式,但是如您所见,第一个项目的ID字段是正确的uuid。
To print this i am doing 为了打印我正在做的
$offers = Offer::list($display, false);
dd($offers);
So offers is the collection. 因此报价就是集合。
If i do... 如果我做...
$offers = Offer::list($display, false);
dd($offers->toArray());
I get the following... 我得到以下...
The id has magically changed into single integers instead of the uuid string I had before. id已神奇地更改为单个整数,而不是我之前拥有的uuid字符串。
Does anyone know why it would be doing this? 有谁知道为什么会这样做? thanks
谢谢
Set the $incrementing
property on your model to false, it is documented here on the primary keys section . 将模型上的
$incrementing
属性设置为false, 这在“主键”部分记录 。 By default Laravel assumes that the id
field on your model is an incrementing integer, that is why models automatically cast id
fields to integers. 默认情况下,Laravel假定模型上的
id
字段是一个递增的整数,这就是为什么模型会自动将id
字段强制转换为整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.