accessories = Accessory::all(); } protected function handle($row) { parent::handle($row); // TODO: Change the autogenerated stub $this->createAccessoryIfNotExists(); } /** * Create an accessory if a duplicate does not exist * * @author Daniel Melzter * @since 3.0 */ public function createAccessoryIfNotExists() { $accessoryId = $this->accessories->search(function ($key) { return strcasecmp($key->name, $this->item['name']) == 0; }); if ($accessoryId !== false) { if (!$this->updating) { $this->log('A matching Accessory ' . $this->item["name"] . ' already exists. '); return; } $this->log('Updating Accessory'); $accessory = $this->accessories[$accessoryId]; $accessory->update($this->sanitizeItemForUpdating($accessory)); if (!$this->testRun) { $accessory->save(); } return; } $this->log("No Matching Accessory, Creating a new one"); $accessory = new Accessory(); $accessory->fill($this->sanitizeItemForStoring($accessory)); if ($this->testRun) { $this->log('TEST RUN - Accessory ' . $this->item["name"] . ' not created'); return; } if ($accessory->save()) { $accessory->logCreate('Imported using CSV Importer'); $this->log('Accessory ' . $this->item["name"] . ' was created'); } $this->jsonError($accessory, 'Accessory'); } }