I'm trying to do that , get list of topics order by who has new post so I create a relation in topic model like that
public function latest_post()
{
return $this->hasOne(Post::class)->latest();
}
then I used the query like that
Topic::where('locale',$this->locale)->with('latest_post')->paginate(15)->sortByDesc('latest_post.created_at');
but it's giving me an error
Collection::render does not exist
so I change the sort
to orderBy
like that
Topic::where('locale',$this->locale)->with('latest_post')->orderBy('latest_post','DESC')->paginate(15);
but this also gives me another error
Unknown column 'latest_post' in 'order clause'
how can solve this issue?