belongsTo('App\Model\TemplateProgram', 'id_template_program'); } public function itemProgram(){ return $this->hasMany('App\Model\ItemProgram', 'id_template_program_detail'); } /** * @return mixed */ public function getTotalPeriodeActiveAttribute() { $total_periode = 0; if(!empty($this->tahunProgramDetail)){ $total_periode = TahunProgramDetail::where('id_template_program',$this->id); $year = date('Y'); $total_periode = $total_periode->whereHas('tahunProgram',function($q) use($year){ $q->where('value',$year); }); //if user not admin if(!empty(Auth::user())){ $getStatus = Role::where('id',Auth::user()->role_id)->value('akses'); if(!empty($getStatus) && $getStatus!='administrator'){ $id_upt = Auth::user()->upt; $total_periode = $total_periode->where('unit',$id_upt); } } $total_periode = $total_periode->count(); } return $total_periode; } /** * @return mixed */ public function getTotalPeriodeAttribute() { $total_periode = 0; if(!empty($this->tahunProgramDetail)){ $total_periode = $this->tahunProgramDetail; //if user not admin if(!empty(Auth::user())){ $getStatus = Role::where('id',Auth::user()->role_id)->value('akses'); if(!empty($getStatus) && $getStatus!='administrator'){ $id_upt = Auth::user()->upt; $total_periode = $total_periode->where('unit',$id_upt); } } $total_periode = $total_periode->count(); } return $total_periode; } }