Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Iam want to get sum of degree for each row with json

Hello I have a problem with PHP laravel with JSON I am saving in filled

  • JSON data name is element_degree
  • The key is the element and the value is the degree

Problem I want show user data and get sum of degree for each user how can I do this ?

This is my data:

Id User Month Element_degree
13 2 2 "{"13":"122","14":"130"}"
14 3 2 "{"13":"100","14":"120"}"
15 4 2 "{"13":"140","14":"100"}"

And this is my code in controller:

$data=empdata::all()

How can I get a sum of degrees for each row from field element_degree for each user ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try this code it will add element_degree_total field in your emp data for each data

$employees = empdata::all();
    foreach($employees as $employee){
        $data = json_decode($employee->element_degree);
        $total = 0;
        foreach ($data as $d) {
             $total += $d;
        }
        $employee->element_degree_total = $total;
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda