/** * Delete an Organization Group. * @param $id * @return \Illuminate\Http\RedirectResponse */ public function delete($id) { $userGroup = $this->userGroup->findOrFail($id); if (!$this->orgGroupManager->deleteGroup($userGroup)) { return redirect()->back()->withResponse(['type' => 'warning', 'code' => ['message', ['message' => 'Organization group could not be deleted.']]]); } return redirect()->back()->withResponse(['type' => 'success', 'code' => ['message', ['message' => 'Organization Group successfully deleted.']]]); }
public function save(array $groupDetails, $id = null) { try { $this->database->beginTransaction(); $userId = $id ? $this->userGroup->findOrFail($id)->user_id : null; $adminData = $this->putUserToGroup($groupDetails); $user = $this->user->firstOrNew(['id' => $userId]); $user->fill($adminData)->save(); $groupData = $this->MakeOrganizationGroup($groupDetails, $user->id); $group = $this->userGroup->firstOrNew(['user_id' => $user->id]); $group->fill($groupData)->save(); $this->database->commit(); $this->logger->info($id ? 'Group information Updated' : 'Organization Group added'); $this->dbLogger->activity($id ? "activity.group_updated" : "activity.group_added", ['group_id' => $group->id]); } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['settings' => $groupDetails]); } }
/** * get groups by user Id * @param $userId * @return mixed */ public function getGroupsByUserId($userId) { $userGroup = $this->userGroup->whereUserId($userId)->first(); return $this->organization->whereIn('id', $userGroup->assigned_organizations)->with(['settings'])->orderBy('name', 'asc')->get(); }