belongsTo('App\Models\ContractTemplate', 'contract_template_id'); } public function contract_template_obligation_dependency() { return $this->hasMany('App\Models\ContractTemplateObligationDependency', 'contract_template_obligation_id'); } public function depend_contract_template_obligation_dependency() { return $this->hasMany('App\Models\ContractTemplateObligationDependency', 'depend_contract_template_obligation_id'); } public function contract_template_obligation_contract_template_dependency() { return $this->hasMany('App\Models\ContractTemplateObligationContractTemplateDependency', 'contract_template_obligation_id'); } public function getHashIdAttribute() { return Hasher::encode('contract_template_obligations', $this->id); } public function getUserHashIdAttribute() { return Hasher::encode('users', $this->user_id); } public function getContractTemplateHashIdAttribute() { return Hasher::encode('contract_templates', $this->contract_template_id); } public function getContractTemplateListAttribute() { return $this->contract_template()->get()->makeHidden(['contract_template_obligation_list']); } public function getContractTemplateObligationDependencyListAttribute() { return $this->contract_template_obligation_dependency() ->where('status', config('constants.contract_template_obligation_dependency.status.active')) ->get()->makeHidden(['contract_template_obligation_list', 'depend_contract_template_obligation_list']); } public function getDependContractTemplateObligationDependencyListAttribute() { return $this->depend_contract_template_obligation_dependency() ->where('status', config('constants.contract_template_obligation_dependency.status.active')) ->get()->makeHidden(['contract_template_obligation_list', 'depend_contract_template_obligation_list']); } public function getContractTemplateObligationContractTemplateDependencyListAttribute() { return $this->contract_template_obligation_dependency() ->where('status', config('constants.contract_template_obligation_contract_template_dependency.status.active')) ->get()->makeHidden(['contract_template_obligation_list']); } public function getUpdatedAtAttribute($date) { return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : ''; } public function getCreatedAtAttribute($date) { return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : ''; } public function getContractTemplateObligationDependencyStructure($contract_template_obligation_id = [], $contract_template_obligation_id_structure = []) { $contract_template_obligation_id = !empty($contract_template_obligation_id) ? Hasher::decode('contract_template_obligations', $contract_template_obligation_id[0]) : $this->id; $contract_template_obligation = ContractTemplateObligation::find($contract_template_obligation_id); if (!empty($contract_template_obligation->contract_template_obligation_dependency_list)) { foreach ($contract_template_obligation->contract_template_obligation_dependency_list as $key => $row) { $contract_template_obligation_id_structure[] = $row->depend_contract_template_obligation_hash_id; if (!empty($row->depend_contract_template_obligation_list)) { return $this->getContractTemplateObligationDependencyStructure([$row->depend_contract_template_obligation_hash_id], $contract_template_obligation_id_structure); } } } return $contract_template_obligation_id_structure; } }