$props = Property::with(['rentalUnit','rentalUnit.floor'])->get()->toArray();
我想用楼层表字段
rentalunit
的字段对floor_name
集合进行排序任何帮助,将不胜感激
最佳答案
将此添加到您的媒体资源模型
public function rentalUnitOrderByFloorName()
{
return $this->rentalUnit()->select('rental_units.*', 'floors.name')->leftJoin('floors', 'floors.rental_unit_id', '=', 'rental_units.id')->orderBy('floors.name');
}
然后
$props = Property::with(['rentalUnitOrderByFloorName','rentalUnitOrderByFloorName.floor'])->get()->toArray();