where('id', $this->attributes['parent_id'])->value('name') ?? '--'; } public function setRoleIdsAttribute($val) { $this->attributes['role_ids'] = '-' . arr2str0($val, '-') . '-'; } public function getRoleIdsAttribute($val) { return str2arr0(trim($val, '-'), '-'); } public static function sonGroup($id) { $str = []; $num = self::query()->where('parent_id', '=', $id)->pluck('id')->toArray(); if (count($num)) { foreach ($num as $k => $v) { $str[] = $v; $ids = self::sonGroup($v); foreach ($ids as $i) { $str[] = $i; } } } return $str; } public static function byRoleGetIds($role_id) { if (login_admin_id() == 1) { return self::query()->pluck('id')->toArray(); } return self::query()->where('role_ids', 'like', "%-{$role_id}-%")->orWhere('role_ids', 'like', "%-0-%")->pluck('id')->toArray(); } }