Support the ongoing development of Laravel.io →
posted 11 years ago
Database

Helo!!, i need, help me please i'm confused with this query, sorry for my english :(

I have this query and work fine

$mensajes = DB::table('users as U')
            ->where('R.c_id_fk', '=', $c_id)
            ->leftJoin('mensajes_reply as R', 'R.user_id_fk', '=', 'U.id')
            ->select('R.cr_id as id_mensaje','R.time as fecha','R.reply as mensaje','U.primer_nombre as nombre','U.apellido_paterno as apellido')
            ->orderBy('R.cr_id', 'asc')
            ->take(10)
            ->get();

But i take last 10 rows with orderby desc, but show data i need in ordeby asc, i try with raw how read in old forum but y can't understand how convert this to raw form how this

$users = DB::table(DB::raw('('.
    DB::table('foo')->orderBy('bar', 'desc')->take(10)->toSql()
.') foo'))->orderBy('bar', 'asc')->get();

Because i use name as other name and this confused me

Thanks!

Last updated 3 years ago.
0

finally i used

return array_reverse($mensajes, true);

with this i can invert result and this work very well and finally i think that this is better using array_reverse, not to force the sql engine.

Regards! if someone could explain how sql, I would appreciate, to understand it in the same way

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.