currentUser) { $this->currentUser = $this->getLoginUser(); } return $this->currentUser; } /** * 当前用户的所有的角色标识的结合 * @return Collection */ protected function listUserRoles():Collection { return $this->getCurrentUser()->roles->pluck('identify'); } /** * 当前用户是否是cp角色 * @return bool */ public function userIsCp():bool { return $this->listUserRoles()->contains('cp'); } /** * 如果当前用户是cp角色,返回cp_name,否则返回null * @return string */ public function getUserCpName():string|null { if($this->userIsCp()) { return DB::table('user_belong_to_cp') ->where([ 'is_enabled' => 1, 'user_id' => $this->getCurrentUser()->id, ])->value('cp_name'); } else { return null; } } }