PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

[FIXED] How to foreach and group like this on blade laravel?

 April 19, 2022     laravel, laravel-blade, php     No comments   

Issue

I'm retrieving tracking data from the DHL API, as follows the data I get : Data API From DHL TRACKING

I use foreach in laravel blade, the result is like this: Foreach on Blade

How to make a foreach group where date in laravel blade like this : View on Website DHL

Please Help all, thank you..


Solution

You can group the result from API by date using Laravel's collection.

@php
    $groupedResult = collect([$apiResult])->groupBy(function($item) {
                      return Carbon::parse($item['timestamp'])->format('Y-m-d');
                  });
@endphp

@foreach($groupedResult as $date => $row)
 {{ $date }}
 @foreach($row as $item)
   // each day's transactions
 @endforeach
@endforeach

But I will suggest to process the data in controller, and then send to the front.



Answered By - Karim Naimy
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing