I have the following request
$latestTrailers = DB::table('game_trailer')
->join('trailers', 'trailers.id', '=', 'game_trailer.trailer_id')
->join('games', 'games.id', '=', 'game_trailer.game_id')
->join('device', 'device.id', '=', 'games.device_id')
->where('game_trailer.bool', 1)
->orderBy('game_trailer.created_at', 'desc')
->select('name', 'trailer_link', 'device_url', 'game_trailer.created_at')
->limit(3)
->get();
And the following result
Collection {#407 ▼
#items: array:3 [▼
0 => {#420 ▼
+"name": "Persona 5"
+"trailer_link": "cc-ClutaN_I"
+"device_url": "ps4"
+"created_at": "2018-02-13 16:32:34"
}
1 => {#395 ▼
+"name": "Persona 5"
+"trailer_link": "cc-ClutaN_I"
+"device_url": "ps3"
+"created_at": "2018-02-13 16:30:36"
}
2 => {#427 ▼
+"name": "Halo 3: ODST"
+"trailer_link": "Zz6FNKawJBc"
+"device_url": "microsoft-xbox-360"
+"created_at": "2018-02-13 16:27:56"
}
]
}
I'd like the "trailer_link" value to be unique. And so make the request select the next entrie in the database if this column is not unique.
I tried the distinct() method but it doesn't work as I only want to use it on only one value.
Are there any equivalents ? Or another way to do it ?