Nikunj Php Nikunj Php - 5 months ago 35
PHP Question

how to sort query results with nested relation column field in laravel?

$props = Property::with(['rentalUnit','rentalUnit.floor'])->get()->toArray();

I want to sort
collection with field of floor table field

Any help would be appreciated

Answer Source

Add this to your Property model

public function rentalUnitOrderByFloorName() 
    return $this->rentalUnit()->select('rental_units.*', '')->leftJoin('floors', 'floors.rental_unit_id', '=', '')->orderBy('');


$props = Property::with(['rentalUnitOrderByFloorName','rentalUnitOrderByFloorName.floor'])->get()->toArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download