statusCount(); $schedules = Schedule::where('last_backup_status', 'Success')->orderBy('updated_at', 'desc')->paginate(10); return ScheduleResource::collection($schedules)->additional(['count' => $count ]); } public function warnings(){ $count = $this->statusCount(); $data = ScheduleResource::collection(Schedule::all()->where('last_backup_status', 'Warning')->sortByDesc('updated_at')); return compact('count','data'); } public function errors(){ $count = $this->statusCount(); $data = ScheduleResource::collection(Schedule::all()->where('last_backup_status', 'Error')->sortByDesc('updated_at')); return compact('count','data'); } public function noschedules(){ $count = $this->statusCount(); // $data = ScheduleResource::collection(Schedule::all()->where('last_backup_status', 'Errors')->sortByDesc('updated_at')); $data = Client::whereDoesntHave('schedules')->get(); return compact('count','data'); } public function norecent(){ $count = $this->statusCount(); $data = ScheduleResource::collection(Schedule::where('last_backup_time', '<=', Carbon::now() ->subHours(48) ->toDateTimeString()) ->get()->sortByDesc('updated_at')); return compact('count','data'); } public function statusCount() { // $results= DB::table('backup_schedules')->select('last_backup_status', DB::raw('count(*) as count'))->groupBy('last_backup_status')->get(); $noschedules = Client::whereDoesntHave('schedules')->count(); $norecent = Schedule::where('last_backup_time', '<=', Carbon::now() ->subHours(48) ->toDateTimeString()) ->count(); $errors = Schedule::where('last_backup_status' , 'Error')->count(); $successful = Schedule::where('last_backup_status' , 'Success')->count(); $warnings = Schedule::where('last_backup_status' , 'Warning')->count(); return compact('noschedules','norecent','errors','successful','warnings'); } }