5 use Discord\Parts\Guild\Role;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class DiscordRole extends Model
13 public static function onUpstreamCreate(Role $role) {
14 $guild = DiscordGuild::firstWhere('guild_id', $role->guild_id);
16 static::sync($guild, $role);
19 public static function onUpstreamUpdate(Role $role) {
20 $guild = DiscordGuild::firstWhere('guild_id', $role->guild_id);
22 static::sync($guild, $role);
25 public static function onUpstreamDelete($role) {
27 $model = static::firstWhere('role_id', $role->id);
32 public static function sync(DiscordGuild $guild, Role $role) {
33 $model = static::firstOrNew([
34 'discord_guild_id' => $guild->id,
35 'role_id' => $role->id,
37 $model->name = $role->name;
38 $model->color = $role->color;
39 $model->position = $role->position;
40 $model->permissions = $role->permissions->bitwise;
44 public function guild() {
45 return $this->belongsTo(DiscordGuild::class);
48 protected $fillable = [