I'm trying to sort a related table without success the original driver looks like this:
$products = Product::orderBy('nombre', 'asc')
->where('user_id', auth()->user()->id)->with('Coment')
->get();
And the way I'm trying is like this:
$products = Product::orderBy('nombre', 'asc')
->where('user_id', auth()->user()->id)->with(['coment' => function ($query) {
$query->orderBy('created_at', 'desc');
}])->get();
but I can not get it to be ordered .. where can the error be?