dispatch('open-grupo-modal'); } public function mount($grupo) { $this->grupo = $grupo; } public function guardar() { if (empty($this->selectedAlumnos)) { session()->flash('error', 'Selecciona al menos un alumno'); return; } $this->grupo->alumnos()->syncWithoutDetaching($this->selectedAlumnos); $this->reset('selectedAlumnos'); $this->dispatch('swal', icon: 'success', title: 'Anexado!', text: 'Se agrego el alumno correctamente', timer: 2000, confirm: false, closeModal: true, reload: 2000 ); $this->dispatch('close-modal'); } public function render() { $user = Auth::user(); $grupo = $this->grupo; $plantelesUsuario = $user->plantelUsuarios->pluck('id'); $alumnos = Alumno::query() ->with(['usuario', 'statusAlumno', 'plan.carreraRel', 'nivelRel']) // ✅ Cambia el 2 por el status correcto ->whereIn('status', [2, 3]) // inscrito o alumno ->where('nivel', $grupo->nivel) ->whereDoesntHave('grupos') ->whereHas('usuario', function ($q) use ($plantelesUsuario) { $q->whereHas('plantelUsuarios', function ($q2) use ($plantelesUsuario) { $q2->whereIn('plantel_user.plantel_id', $plantelesUsuario); }); }) ->orderByRaw("CASE WHEN plan_id = {$grupo->plan_id} THEN 0 ELSE 1 END") ->orderByRaw("CASE WHEN nivel = {$grupo->nivel} THEN 0 ELSE 1 END") ->get(); return view('livewire.grupo-alumno', [ 'alumnos' => $alumnos, ]); } }