Any suggestions or ideas for me to explore?
Add pivot table data to model query results?
I've set up a simple little laravel site with users, playlists, and videos. Users can create videos, they can create playlists, and they can add ANY videos (that they or someone else created) to their own playlists.
I'm trying to figure out how to perform a single query to lookup ALL of the playlists that a user has created, and somehow add an additional column to the output listing true/false if the playlist features a specific video by ID.
In other words, I'm trying to get an array of all the playlists a user owns... BUT with an additional piece of data for each playlist that specifies whether or not a specific video id has already been added to the playlist.
I started with something like this to get just the playlists that don't already include the video. But I can't figure out how to include all playlists with some additional data regarding the possible inclusion of the specific video.
$playlists = auth()->user()->playlists()
->whereNotIn('id', function($query) use ($video) {
$query->select('playlist_id')
->from('playlist_video')
->where('video_id', $video->id);
})->get();
Please or to participate in this conversation.