$guild->id, ]); $model->name = $guild->name; $model->icon_hash = $guild->icon_hash; $model->owner = $guild->owner_id; $model->locale = $guild->preferred_locale; $model->save(); $role_ids = []; foreach ($guild->roles as $role) { DiscordRole::sync($model, $role); $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)->orderBy('position'); } public function roles() { return $this->hasMany(DiscordRole::class)->orderBy('position'); } protected $fillable = [ 'guild_id', ]; }