Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mprythero's avatar

orderBy/sortBy Relationship using a field in a Relationship's Relationship

I have the following relationship in my modal agentBilling:

    public function batches(){
        return $this->hasMany(agent_billings_batches::class,'agentBillingPeriod','id');
    }

And in the agent_billings_batches model, I've got the following relationship:

    public function date(){
            return $this->hasOne(agent_billings_dates::class,'id','dateID');
    }

The agent_billings_dates model has a date fields labeled simply date. Is there a way I could sort the batches relationship in the agentBilling model by the date field in the date relationship of the agent_billings_batches? Or is there a way around this?

Thanks! Matt

0 likes
1 reply
Snapey's avatar

I think a join of the child model is the only way to go

Please or to participate in this conversation.