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

145
Views
Not able to fetch the json data in laravel controller

I want to fetch the data from children field or get count of children.

I am fetching like this: $temp = json_decode($request->get('tempData');

Here is my json payload:

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

You can get children count for all items on tempData array by using collection

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

to get result of children count for every id:

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

0

You could create a new array and push children in that array with a foreach loop.

$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!