$city = City::with('station')->where('name',$town)->first();
$townID = 1;
$townComments = TownComment::where('town_id',$townID)->get();
$city->town_comments = $townComments;

当我这样做时,town_comments的结果仅显示booleantimestampsincrementingexists

我在这里做错了什么?

这是它的样子:
{
id: "1",
name: "tokyo",
similar_stations: {
    timestamps: false,
    incrementing: true,
    exists: true
}
}

最佳答案

之所以这样显示,是因为$townComments是自动编码为JSON的对象,我忘记了阅读它的引用,但这是解决方案。

$city->town_comments = $townComments->toArray();

关于Laravel 4- Eloquent 结果仅在被分配到另一个对象内部时显示(时间戳,递增,存在),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17466643/

10-12 16:33