Create a nova relationship.
public function novaComments()
{
return $this->comments()->orderBy('columnName');
}
Then in Nova use:
HasMany::make('Comments', 'novaComments')
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i have post resource and comment
when i show up post detail page i want to list comments order_by field not by id , how could i add that
when i added the query into relation it works but i want to effect only on nova not all project
Yes, if you make it messy, it will be messy. There is no way around it. What you can do is use indexQuery method on Nova Comment resource where you will add that ordering, but then it will affect relationships as well as when you visit Comments in Nova. Then you can based on request change that query, but it all depends on what you need.
Please or to participate in this conversation.