dackl's avatar
Level 4

sqlsrv pagination not working using withCount and orderBy

Hi, I'm trying to sort my collection with pagination by relation count. The first page ist working fine, all other pages are showing following Error: Invalid column name 'live'.

Does anyone have a solution for this?

My Code:

$events = Event::withCount([
            'tags as live' => function ($query) {
                $query->where('tag_id', 11342);
            }
        ])
        ->orderBy('live', 'desc')
        ->paginate(5);
0 likes
1 reply

Please or to participate in this conversation.