![](/img/trans.png)
[英]How to sort the results by a relation Dynamic Laravel and Eloquent
[英]how to sort query results with nested relation column field in laravel?
$props = Property::with(['rentalUnit','rentalUnit.floor'])->get()->toArray();
我想用楼层表字段floor_name
字段对rentalunit
集合进行排序
任何帮助,将不胜感激
将此添加到您的媒体资源模型
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.