public function getIndex()
 {
     if (!ACL::hasPermission('visitWellPhotos')) {
         return redirect(route('home'))->withErrors(['Você não pode acessar a página Visit Bem - Fotos.']);
     }
     $visitWellPhotos = VisitWellPhotos::orderBy('date', 'DESC')->get();
     foreach ($visitWellPhotos as $photo) {
         array_set($photo, 'date', Carbon::createFromFormat('Y-m-d', $photo->date)->format('d/m/Y'));
     }
     return view('admin.visitWellPhotos.index')->with(compact('visitWellPhotos'));
 }
 public function filterPhotos(Request $request)
 {
     $page = 'visite-bem';
     $websiteSettings = \App\Exceptions\Handler::readFile("websiteSettings.json");
     $pages = Pages::where('slug', '=', $page)->first();
     $this->validate($request, ['year' => 'required_without:slug', 'month' => 'required_with:year', 'slug' => 'required_without:year'], ['year.required_without' => 'Você precisa buscar pela data', 'month.required_with' => 'Você precisa informar o mês', 'slug.required_without' => 'ou pela turma']);
     $years = ['' => 'Ano'];
     $consultYearMoreOld = VisitWellPhotos::orderBy('date', 'asc')->first();
     $yearMoreOld = Carbon::createFromFormat('Y-m-d', $consultYearMoreOld->date)->format('Y');
     for ($i = date('Y'); $i >= $yearMoreOld; $i--) {
         $years[$i] = $i;
     }
     $months = ['' => 'Mês'];
     for ($i = 1; $i <= 12; $i++) {
         if ($i < 10) {
             $i = "0" . $i;
         }
         $months[$i] = VisitWellPhotos::portugueseMonthName($i);
     }
     $gallery = VisitWellPhotos::orderBy('date', 'desc');
     if (isset($request->year) and !empty($request->year) and isset($request->month) and !empty($request->month) and empty($request->slug)) {
         $dateStart = $request->year . '-' . $request->month . '-01';
         $dateEnd = $request->year . '-' . $request->month . '-31';
         $gallery->whereBetween('date', [$dateStart, $dateEnd]);
     } else {
         if (isset($request->slug) and !empty($request->slug) and empty($request->year) and empty($request->month)) {
             $gallery = $gallery->where('slug', '=', $request->slug);
         } else {
             return redirect('/visite-bem/fotos')->withErrors(['Você deve filtrar pela data ou pela turma!']);
         }
     }
     $gallery = $gallery->get();
     foreach ($gallery as $photo) {
         array_set($photo, "date", Carbon::createFromFormat('Y-m-d', $photo->date));
     }
     $allGalleries = VisitWellPhotos::orderBy('date', 'desc')->get();
     foreach ($allGalleries as $item) {
         array_set($item, "date", Carbon::createFromFormat('Y-m-d', $item->date));
     }
     return view('website.visitWell.photos')->with(compact('page', 'pages', 'websiteSettings', 'years', 'months', 'gallery', 'allGalleries', 'request'));
 }