I have problems ordering from top to bottom my join with query builder

0

I have problems ordering the query from highest to lowest by the date "created_at" it does not throw error and if it shows me the data of the query but only it does not order them you are the code

$listado = DB::table('lotes')->join('producciondiarias', function ($join)use($user_id){
                                $join->on('lotes.id','=','producciondiarias.lote_id')
                                ->where('lotes.user_id','=',$user_id)                                      
                                ->orderBy('producciondiarias.created_at','desc');
                                })->get();
    
asked by Jean Carlos Hernandez 22.11.2017 в 20:30
source

1 answer

0

I solved it, my problem is that it was wrong where I grouped, the correct way is this

$listado = DB::table('lotes')->join('producciondiarias', function ($join)use($user_id){
                                $join->on('lotes.id','=','producciondiarias.lote_id')
                                ->where('lotes.user_id','=',$user_id);
                                })->orderBy('producciondiarias.created_at','desc')->get();
    
answered by 22.11.2017 / 20:43
source