]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/DiscordGuild.php
sync discord channels
[alttp.git] / app / Models / DiscordGuild.php
index 361d6a911b54875ec8afdcf0d9b88c9495aaa0c0..84fd77bc4af0b785ff7df37aaf3ff3a1f899dc9d 100644 (file)
@@ -35,6 +35,17 @@ class DiscordGuild extends Model
                        $role_ids[] = $role->id;
                }
                $model->roles()->whereNotIn('role_id', $role_ids)->delete();
+
+               $channel_ids = [];
+               foreach ($guild->channels as $channel) {
+                       DiscordChannel::sync($model, $channel);
+                       $channel_ids[] = $channel->id;
+               }
+               $model->channels()->whereNotIn('channel_id', $channel_ids)->delete();
+       }
+
+       public function channels() {
+               return $this->hasMany(DiscordChannel::class);
        }
 
        public function roles() {