$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();

09-10 22:51