title: How to fix laravel collection chunk loop once?
body: <p>I have a problem with laravel collection with chunk result. It run only one time in loop.</p>
  
  <p>I have 204 elements in array and I want to split it as 100 each by using laravel collection helper. It must run in three times but I got only once.</p>
  
  <pre class="lang-php prettyprint-override"><code>    private function __migrateDistricts()
      {
          DB::beginTransaction();
          try {
              $file = 'resources/csv/districts.csv';
              $csv = array_map('str_getcsv', file($file));
              $table = 'districts';
              $collection = collect($csv);
              $arr_districts = array();
              foreach ($collection-&gt;chunk(100) as $districts) {
                  foreach ($districts as $dist) {
                      array_push($arr_districts, $this-&gt;__transformDistricts($dist));
                  }
                  DB::table($table)-&gt;insert($arr_districts);
                  DB::commit();
              }
          } catch (\Exception $e) {
              DB::rollBack();
          }
      }
  
      private function __transformDistricts($district)
      {
          $code = substr($district[3],0,2);
          $pro = DB::table('provinces')-&gt;where('code', $code)-&gt;first();
          return [ 
              'province_id' =&gt; $pro-&gt;id,
              'name_kh' =&gt; $district[1],
              'name_en' =&gt; $district[2],
              'code' =&gt; $district[3],
          ];
      }
  
  </code></pre>
  
  <p>After I run the I got only 100 records in table. It should be 204 records in table. What is wrong with my code? Thanks</p>