attributeValueRepository->save(array_merge($data, [ 'entity_id' => $organization->id, ])); return $organization; } /** * Update. * * @param int $id * @param array $attribute * @return Organization */ public function update(array $data, $id, $attributes = []) { if (isset($data['user_id'])) { $data['user_id'] = $data['user_id'] ?: null; } $organization = parent::update($data, $id); /** * If attributes are provided then only save the provided attributes and return. */ if (! empty($attributes)) { $conditions = ['entity_type' => $data['entity_type']]; if (isset($data['quick_add'])) { $conditions['quick_add'] = 1; } $attributes = $this->attributeRepository->where($conditions) ->whereIn('code', $attributes) ->get(); $this->attributeValueRepository->save(array_merge($data, [ 'entity_id' => $organization->id, ]), $attributes); return $organization; } $this->attributeValueRepository->save(array_merge($data, [ 'entity_id' => $organization->id, ])); return $organization; } /** * Delete organization and it's persons. * * @param int $id * @return @void */ public function delete($id) { $organization = $this->findOrFail($id); DB::transaction(function () use ($organization, $id) { $this->attributeValueRepository->deleteWhere([ 'entity_id' => $id, 'entity_type' => 'organizations', ]); $organization->delete(); }); } }