示例:我使用用户模型$object = User::find($id);进行查询当我返回$object时。然后它返回{"balance" => 1, "id" => 2}但是当我返回$object->balance时。然后返回空,我尝试了gettype,它返回对象。更新:当我尝试json_decode($object, true)['balance']。是工作这是怎么了?为什么我无法从原始$object访问它?请有人帮我解决这个问题。谢啦,谢啦
$object = User::find($id);
$object
{"balance" => 1, "id" => 2}
$object->balance
gettype
json_decode($object, true)['balance']
kkbh8khc1#
如果$balance = $object->balance;不适合你,那么你可以尝试以下操作:
$balance = $object->balance;
$object = User::find($id); $attributes = $object->getAttributes(); $balance = $attributes['balance']; // or $balance = $object->toArray()['balance'];
字符串
1条答案
按热度按时间kkbh8khc1#
如果
$balance = $object->balance;
不适合你,那么你可以尝试以下操作:字符串