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

2

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

4 Comments

In this situation, make a join!
if i am applying join than it removing some rows from results i want
Left join won't do that!
i have already try with it left join but i want it without join

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.