我有一个雄辩的模型,我想在一次调用中返回多个查询的结果, 我希望它在一个数组中:
public static function show_workplace($id) {
//calculate 3 queries with queryBuilder and return their results in an array
return [query1 , query2 ,query3]
}
我认为返回一个查询结果数组会以某种方式混淆它。例如,当我返回时
return query1;
没关系。 但是当我回来时
return [query1,query1]
返回
[{"incrementing":true,"timestamps":true,"exists":true},{"incrementing":true,"timestamps":true,"exists":true}]
这些字段不是数据库的真实字段..!
有什么想法我做错了吗?在一个函数中返回多个查询只是糟糕的设计,还是我只是遗漏了其他东西?
答案 0 :(得分:0)
在查询上使用toArray解决它:
return [Workplace::find(13)->toArray(),Workplace::find(13)->toArray()];
如果有人能解释这里发生的事情会很好......文档对此非常模糊。