Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
No se pueden obtener los datos json en el controlador laravel

Quiero obtener los datos del campo de niños u obtener el recuento de niños.

Estoy obteniendo así: $temp = json_decode($request->get('tempData');

Aquí está mi carga útil json:

 tempData:[{ "id":"c625", "name":"Chapter 1", "children":[ { "id":3, "type":"study material", "content":"Demo Study Material Title 2" }, { "id":4, "type":"study material", "content":"Demo Study Material Title 3" }, { "id":5, "type":"study material", "content":"Demo Study Material Title 4" } ], "type":"chapter" } ]
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede hacer que los niños cuenten para todos los elementos en la matriz tempData usando la colección

 collect(json_decode($request->get('tempData'), true)) ->mapWithKeys(fn($item) => [$item['id'] => count($item['children'])]) ->all();

para obtener el resultado del recuento de niños para cada identificación:

 [ "c625" => 3 ]
over 4 years ago · Santiago Trujillo Report

0

Podría crear una nueva matriz y empujar a los niños en esa matriz con un bucle foreach.

 $temp = json_decode($request->get('tempData'); $children = array(); $child_count = 0; foreach ($temp['children'] as $child) { $child_count++; array_push($children, $child); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!