foreach ($sgEntry['channels'] as $sgChannel) {
$ext_ids[] = 'sg:'.$sgChannel['id'];
}
- $episode->channels()
- ->where('ext_id', 'LIKE', 'sg:%')
- ->whereNotIn('ext_id', $ext_ids)
- ->detach();
+ $channels = $episode->channels()
+ ->where('ext_id', 'LIKE', 'sg:%')
+ ->whereNotIn('ext_id', $ext_ids)
+ ->get();
+ if (!$channels->isEmpty()) {
+ $episode->channels()->detach($channels->pluck('id'));
+ }
}
private function syncChannel(Episode $episode, $sgChannel) {