Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel how to nested foreach

//Laravel collection has a method that helps you group the collection. I think you can do this here.

$groupedQuarterly = $dth->mapToGroups(function ($item, $key) {
    return [$item['triwulan'] => $item];
})->toArray();

return view('Triwulan.index',compact('groupedQuarterly'));
This should yield something similar to:

[
  4 => [
    0 => [
      "id" => 2
      "kode_akun" => "bagus"
      "jenis_pajak" => "bagus"
      "nominal_pajak" => "50000"
      "npwp" => "Value"
      "nama_wp" => "Bagus"
      "ntpn" => "1234"
      "id_billing" => "123124"
      "keperluan" => "asdas"
      "bulan" => "Oktober"
      "triwulan" => "4"
      "created_at" => "2022-04-28 19:26:42"
      "updated_at" => "2022-04-28 19:26:42"
    ]
    1 => [
      "id" => 1
      ...
      "bulan" => "Nov"
      "triwulan" => "4"
      "created_at" => "2022-04-28 19:26:42"
      "updated_at" => "2022-04-28 19:26:42"
    ]
  ]
  3 => [
    0 => [
          ...
          "triwulan" => "3"
     ]
  ]
]
//where 4 and 3 indicates the "triwulan" id/number. With this I think it'd be easier for you to manipulate the views.

//and in your view:

@foreach( $$groupedQuarterly as $i => $quarter )
<div>
  Quarter {{ $i }}
  @foreach( $qurater as $month )
   <div>{{ $month["bulan"] }}</div>
  @endforeach
</div>
@endforeach
Comment

laravel how to nested foreach

$groupedQuarterly = $dth->mapToGroups(function ($item, $key) {
    return [$item['triwulan'] => $item];
})->toArray();

return view('Triwulan.index',compact('groupedQuarterly'));
Comment

laravel how to nested foreach

[
  4 => [
    0 => [
      "id" => 2
      "kode_akun" => "bagus"
      "jenis_pajak" => "bagus"
      "nominal_pajak" => "50000"
      "npwp" => "Value"
      "nama_wp" => "Bagus"
      "ntpn" => "1234"
      "id_billing" => "123124"
      "keperluan" => "asdas"
      "bulan" => "Oktober"
      "triwulan" => "4"
      "created_at" => "2022-04-28 19:26:42"
      "updated_at" => "2022-04-28 19:26:42"
    ]
    1 => [
      "id" => 1
      ...
      "bulan" => "Nov"
      "triwulan" => "4"
      "created_at" => "2022-04-28 19:26:42"
      "updated_at" => "2022-04-28 19:26:42"
    ]
  ]
  3 => [
    0 => [
          ...
          "triwulan" => "3"
     ]
  ]
]
Comment

laravel how to nested foreach

@foreach( $$groupedQuarterly as $i => $quarter )
<div>
  Quarter {{ $i }}
  @foreach( $qurater as $month )
   <div>{{ $month["bulan"] }}</div>
  @endforeach
</div>
@endforeach
Comment

PREVIOUS NEXT
Code Example
Php :: oops concepts in php 
Php :: php return multiple values 
Php :: php require once 
Php :: get array value in php 
Php :: yii2 migration --fields foreign 
Php :: auto reload for laravel 
Php :: socket in laravel 
Php :: -sale_price 
Php :: install all php extensions ubuntu 20.04 
Php :: console.log for php 
Php :: magento 2 colllection set select 
Php :: php glob sort by unsigned int 
Php :: Laravel SPA cors 
Php :: Generating Random String In PHP Using random_bytes() function. (Cryptographically Secure) 
Php :: laravel event listener 
Php :: laravel controller subfolder 
Php :: extract in php 
Php :: how to disable a button in a blade file 
Php :: How do I display logged-in username IF logged-in? site:wordpress.stackexchange.com 
Php :: check array has keys in php 
Php :: php while select query 
Php :: php version not update after windows env file 
Php :: eloquent firstorcreate 
Php :: php initialize two dimensional array dynamically 
Php :: str_contains php 5 
Php :: php current page 
Php :: no sass folder in laravel 
Php :: selecting data from two tables in database php 
Php :: laravel collection nth method 
Php :: envoyer des donnees js a php 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =