我有一个表<代码>Quotes,与QuoteDetails
表有着一对一的关系。
表格结构如下:
return $this->quotes->with( quotedetails )
->orderBy( created_at , DESC )->paginate(10);
成果:
{
"current_page":1,
"data":[
{
"id":2,
"subject":"demo",
"quotedetails":[
{
"id":2,
"quotes_id":2,
"description":"testing data",
"total":1080
},
{
"id":3,
"quotes_id":2,
"description":"testing",
"total":180
}
]
},
{
"id":1,
"subject":"demo",
"quotedetails":[
{
"id":1,
"quotes_id":1,
"description":"data",
"total":360
}
]
}
],
"per_page":10,
"prev_page_url":null,
"to":2,
"total":2
}
我想列入<代码>引述细节>的总和<代码>。 页: 1 我不肯定应该如何做到这一点。
在这方面,我是如何在我的模型(Quotes
)中查询的。
public function quotedetails(){
return $this->hasMany( AppModelsQuotesDetail , quotes_id , id );
}
如何获得<代码>总。
www.un.org/Depts/DGACM/index_spanish.htm 这里是预期产出()的方法。
{
"current_page":1,
"data":[
{
"id":2,
"subject":"demo link data",
"quotesum": 1260
},
{
"id":1,
"subject":"demo",
"quotesum": 360
}
],
"per_page":10,
"prev_page_url":null,
"to":2,
"total":2
}