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

Can't get this to work properly. The results are not ordered by date and I get duplicates for each comment and view. This is what I'm using.


public static function getComments($id) {
        $comments = DB::table('revisions')
                ->join('comments', 'comments.photo_id', '=', 'revisions.id')
                ->join('views', 'pid', '=', 'revisions.id')
                ->select('comments.comment', 'comments.uname', 'comments.id', 
                        'comments.created_at as comments_date', 'views.user', 'views.created_at as views_date')
                ->where('revisions.id', '=', $id)
                ->orderBy('comments_date', 'desc', 'views_date', 'desc')
                ->get();
        return $comments;
    }

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

eugael eugael Joined 25 Feb 2014

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.