public function googleSaveCalendar($user_id, Request $request)
 {
     $calendar_id = $request->input('calendar_id');
     $data = GoogleUserCalendar::where('user_id', '=', $user_id)->where('calendar_id', '=', $calendar_id)->first();
     $msg = "Error";
     if ($data) {
         GoogleUserCalendar::destroy($data->id);
         $msg = "Calendar is disabled";
     } else {
         GoogleUserCalendar::create(['user_id' => $user_id, 'calendar_id' => $calendar_id]);
         $msg = "Calendar is enabled";
     }
     return response()->json(['msg' => $msg], 200);
 }
 public function events($company_id, Request $request)
 {
     $google_calendars = [];
     $users = Auth::user();
     if (Auth::user()->role != "worker") {
         $users = User::whereHas('company', function ($q) use($company_id) {
             $q->where('companies.id', '=', $company_id);
         })->select('id', 'events_color')->get();
         $users = array_column($users->toArray(), 'events_color', 'id');
         foreach ($users as $user_id => $event_color) {
             $google_calendars[$user_id] = GoogleUserCalendar::freeBusy($user_id, $request->get('start'), $request->get('end'));
         }
         $jsonResponse = Roster::eventsJSON($company_id, ['start' => $request->get('start'), 'end' => $request->get('end')]);
     } else {
         $jsonResponse = User::events(Auth::user()->id, ['start' => $request->get('start'), 'end' => $request->get('end')]);
         $google_calendars[Auth::user()->id] = GoogleUserCalendar::freeBusy(Auth::user()->id, $request->get('start'), $request->get('end'));
     }
     foreach ($google_calendars as $user_id => $google_calendar_list) {
         foreach ($google_calendar_list as $calendar) {
             $events = $calendar->busy;
             if (count($events) > 0) {
                 foreach ($events as $event) {
                     array_push($jsonResponse, (object) ["id" => "google_" . rand(100, 700), "resourceId" => $user_id, "start" => $event->start, "end" => $event->end, "rendering" => "background", "color" => $users[$user_id]]);
                 }
             }
         }
     }
     return response()->json($jsonResponse);
 }