hasMany('App\Model\ItemProgram', 'id_template'); } public function templateProgramDetail(){ return $this->hasMany('App\Model\TemplateProgramDetail', 'id_template_program'); } public function templateProgramRole(){ return $this->hasMany('App\Model\TemplateProgramRole', 'id_template_program'); } public function tahunProgram(){ return $this->belongsToMany('App\Model\TahunProgram', 'tb_tahun_program_detail','id_tahun_program', 'id_template_program'); } public function tahunProgramDetail(){ return $this->hasMany('App\Model\TahunProgramDetail', 'id_template_program'); } /** * @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; } }