【发布时间】:2016-08-21 22:59:00
【问题描述】:
表 A = 库存 |表 B = ItemAssociation |表 C = ItemValue
我有表 A、B 和 C。A 和 B 是一对一的关系,B 和 C 是一对一的关系。我目前正在使用 HasManyThrough 关系来达到这个目的:
public function item(){
return $this->hasManyThrough('App\ItemValue','App\ItemAssociation','id','id');
}
在我的控制器中:
public function orm(){
$inventory = Inventory::getAssocBySteamID(76561198124900864)->get();
$i = 0;
foreach($inventory as $inv){
$this->data[$i] = $inv->item()->get();
$i++;
}
return $this->data;
}
在哪里 Inventory::getAssocBySteamID:
public static function getAssocBySteamID($id){
return SELF::where('steamid64','=',$id);
}
这将返回我需要的所有数据,但是,我需要按表 C 中的一列,即 ItemValue 模型对其进行排序。
任何帮助将不胜感激。
【问题讨论】:
标签: php database laravel orm eloquent