0

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]);
      //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.

user163831
  • 1,031
  • 3
  • 13
  • 25
  • Have you tried seeding with the --verbose flag to get a bit more information about the exception? – Ben Swinburne Nov 13 '17 at 09:55
  • No, thank You! But somehow it is working now and I don't see what in it is different... – user163831 Nov 13 '17 at 23:18
  • I found that having opened some csvs in Numbers/Excel/TextEdit etc it added characters i couldn't see which the CSV reader didn't like. Exporting from source and importing worked. Exporting, opening, closing and importing failed. Might be something to consider. – Ben Swinburne Nov 13 '17 at 23:44

0 Answers0