Exemplo n.º 1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $distancia_total = Registro::getDistanciaTotal();
     if (is_object($distancia_total)) {
         $distancia_total = '0';
     }
     $tops = Registro::select()->whereNull('tutti')->orderBy('distancia', 'DESC')->orderBy('updated_at', 'DESC')->take(5)->get();
     $lugar = ['Primer', 'Segundo', 'Tercer', 'Cuarto', 'Quinto'];
     $i = 0;
     foreach ($tops as $key => $top) {
         if ($top->imagen) {
             $top->orientacion = self::imageOrientation($top->imagen);
         } else {
             $top->orientacion = null;
         }
         $top->lugar = $lugar[$i];
         $i++;
     }
     $count = Registro::select()->whereNull('tutti')->count();
     $skip = 5;
     $limit = $count - $skip;
     $corredores = Registro::select()->whereNull('tutti')->skip($skip)->take(20)->orderBy('distancia', 'DESC')->orderBy('updated_at', 'DESC')->get();
     foreach ($corredores as $key => $corredor) {
         if ($corredor->imagen) {
             $corredor->orientacion = $this->imageOrientation($corredor->imagen);
         } else {
             $corredor->imagen = 'http://12kchocho.org.mx/img/avatarchocho.png';
             $corredor->orientacion = null;
         }
     }
     if (Request::ajax()) {
         return Response::json($corredores);
     } else {
         return view('index')->with(compact('corredores', 'tops', 'distancia_total', 'filename'));
     }
 }