Problem to order related table laravel

2

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?

    
asked by Lendy Rodriguez Silva 01.12.2018 в 14:12
source

0 answers