Level 11
whereHas() is used for conditioning the data loaded in relationships. If you want to order then I believe you should attempt to do it on the with() method so that it eager loads the relation as you want it.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using yajradatatables , but unfortunately im not able to order by name ,
$a = $query->whereHas('activity_logs' , function ($q) use ($order){
$q->morphWith('causer', ['App\Domains\Auth\Models\User'], function ($q2) use ($order){
$q2->orderBy('name',$order);
});
});
Please or to participate in this conversation.