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

I want to sort rentalunit collection with field of floor table field floor_name

Any help would be appreciated

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
Nikunj Php
  • 35
  • 5

1 Answers1

0

Add this to your Property model

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

Then

$props = Property::with(['rentalUnitOrderByFloorName','rentalUnitOrderByFloorName.floor'])->get()->toArray();
Morteza Rajabi
  • 2,763
  • 2
  • 24
  • 27