dimanche 12 novembre 2017

Why am I getting an irrelevant ErrorException for blank csv columns in attempt to import with League\CSV?

I have this:

  $csv = Reader::createFromPath(__DIR__.'/data/manufacturers.csv', 'r');
  $csv->setHeaderOffset(0);
  $headers = $csv->getHeader();
  $records = $csv->getRecords();
  foreach ($records as $r) {
    $cols = array_combine($headers, $r);
    $i = [];
    foreach($headers as $h)
    {
      if($h == 'dealer') $cols[$h] = boolval($cols[$h]) ?: false;
      //elseif(empty($cols[$h])) $cols[$h] == '...';
      print "$h\n"; var_dump($cols[$h]);
      $i[$h] = $cols[$h];
    }
    \Modules\Cars\Entities\Manufacturer::create($i);
  }

and as you can see I'm doing some troubleshooting, the commented out line does nothing, and I don't know why. Resulting output:

Seeding: Modules\Cars\Database\Seeders\ManufacturersTableSeeder
title
string(15) "Rolls"
dealer
bool(false)
url
string(0) ""
summary
string(0) ""
logo
string(0) ""

  [ErrorException]
  A non well formed numeric value encountered

The url column in the first row is blank, as was the dealer one, until I made it 0 to test this. How do I remedy it? Some fields are going to be blank. I tried setting them to null, too.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AA3Gz6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire