jeudi 25 avril 2019

Can i use offset (skip) with GroupBy?

Below is my query, and i have added some description what i want.

$recommendedByVideoId = RecommendedVideo::selectRaw('video_id,id')
                ->orderBy('played_count', 'desc')
                ->orderBy('updated_at', 'desc')
                ->get()
                ->skip(3)
                ->take(2)
                ->groupBy('video_id')

Below is my query result :

        [video_id_1] => [record1, record2, record3, record4, record5],
        [video_id_2] => [record1, record2, record3, record4, record5],
        [video_id_3] => [record1, record2, record3, record4, record5],
        [video_id_4] => [record1, record2, record3, record4, record5],
        [video_id_5] => [record1, record2, record3, record4, record5, record6, record7],

Expected Result should be something like:

        [video_id_1] => [record4, record5],
        [video_id_2] => [record4, record5],
        [video_id_3] => [record4, record5],
        [video_id_4] => [record4, record5],
        [video_id_5] => [record4, record5],

Please help me to write out query, that skip records from inner collection not from outer.

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire