$city = City::with('station')->where('name',$town)->first();
$townID = 1;
$townComments = TownComment::where('town_id',$townID)->get();
$city->town_comments = $townComments;
执行此操作时,town_comments
的结果仅显示boolean
,timestamps
和incrementing
的{{1}}。
我在这里做错了什么?
这是它的样子:
exists
答案 0 :(得分:18)
它显示的是因为$townComments
是一个自动编码为JSON
的对象,我忘记了我读到它的参考,但这是解决方案。
$city->town_comments = $townComments->toArray();