table = New TahunProgramDetail; $this->middleware('auth'); } public function index(){ $year = date('Y'); // Check the tahunProgram table for an entry with status = 1 and deleted_at is null $tahunProgram = TahunProgram::where('status', 1) ->whereNull('deleted_at') ->value('value'); // Get the 'value' column which should be the year // If an entry is found, use that year if ($tahunProgram) { $year = $tahunProgram; } $getStatus = Role::where('id',Auth::user()->role_id)->value('akses'); $data_pk = $this->table->with('templateProgram','tahunProgram'); $data_pk = $data_pk->whereHas('tahunProgram',function($query) use ($year){ $query->where('value',$year); }); $data_pk = $data_pk->whereHas('templateProgram',function($q){ $q->where('tipe',0); }); $data_pk = $data_pk->distinct('id_template_program')->get(); $data_non_pk = $this->table->with('templateProgram','tahunProgram'); $data_non_pk = $data_non_pk->whereHas('tahunProgram',function($query) use ($year){ $query->where('value',$year); }); $data_non_pk = $data_non_pk->whereHas('templateProgram',function($q){ $q->where('tipe',1); }); $data_non_pk = $data_non_pk->distinct('id_template_program')->get(); return view('program.program',compact('data_pk','data_non_pk','getStatus')); } }