File: /var/www/html/xfacil.desafio.com.py/app/Http/Livewire/Ranking.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Equipo;
use App\Models\Matricula;
use Carbon\Carbon;
use Auth;
use DB;
class Ranking extends Component{
public $fecha_inicio,$fecha_fin;
public function mount(){
$this->fecha_inicio=Carbon::now()->format('Y')."-01-01";
$this->fecha_fin=Carbon::now()->format('Y-m-d');
}
public function render(){
$matricula=Matricula::where('usuario_id',Auth::id())->first();
$equipo=Equipo::where('id',$matricula->equipo_id)->first();
if($this->fecha_inicio && $this->fecha_fin){
$equipos = Equipo::where('id', '!=', 30)
->where('id', '!=', 37)
->where('estado', 1)
->whereDate('created_at', '>=', Carbon::parse($this->fecha_inicio)->toDateString())
->whereDate('created_at', '<=', Carbon::parse($this->fecha_fin)->toDateString())
->where('nivel', $equipo->nivel)
->orderBy(DB::raw("CAST(`puntos` AS SIGNED) + CAST(`puntos_extras` AS SIGNED)"), 'desc')
->get();
} else {
$equipos = Equipo::where('id', '!=', 30)
->where('id', '!=', 37)
->where('estado', 1)
->where('nivel', $equipo->nivel)
->orderBy(DB::raw("CAST(`puntos` AS SIGNED) + CAST(`puntos_extras` AS SIGNED)"), 'desc')
->get();
}
return view('livewire.ranking',["equipos" => $equipos]);
}
}