subWeek()->startOfWeek(); // Lunes anterior $toDate = Carbon::now()->subWeek()->endOfWeek(); // Domingo anterior $ventas = Venta::with(['cliente', 'detalles.producto', 'detalles.variante']) ->whereBetween('created_at', [$fromDate, $toDate]) ->get(); // Obtener todos los usuarios con el rol 'Administrador' $administradores = User::role('Administrador')->get(); if ($administradores->isEmpty()) { $this->warn('No se encontraron usuarios con el rol Administrador.'); return; } foreach ($administradores as $admin) { Mail::to($admin->email)->send(new ReporteVentasMail($ventas, $fromDate, $toDate, $admin->email)); $this->info("Reporte enviado a: {$admin->email}"); } $this->info('Todos los reportes han sido enviados a los administradores.'); } }