表A = 库存 | 表B = 物品关联 | 表C = 物品数值
我有表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);
}
这会返回我所需的所有数据,但是我需要按Table C中ItemValue模型中的一列进行排序。
非常感谢您的帮助。
->orderBy('ItemValue.item_price')
- Filip Koblańskiaverage_price
排序,这就是我所需要的。 - Nuled