public function importData($results, $sessionKey = null) { $firstRow = reset($results); /* * Import */ foreach ($results as $row => $data) { try { /* * Find or create */ $product = Product::make(); $productExists = $product->exists; /* * Set attributes */ $product->category_id = 4; $product->is_shown = 1; $product->partID = array_get($data, 'partID'); $price = array_get($data, 'price'); $product->price = $price ? $price : 0; $product->name = array_get($data, 'name'); $product->save(); /* * Log results */ if ($productExists) { $this->logUpdated(); } else { $this->logCreated(); } } catch (Exception $ex) { $this->logError($row, $ex->getMessage()); } } }
public function getProducts() { $catId = $this->property('id'); return Product::where('category_id', $catId)->isShown()->orderBy('name', 'asc')->get(); }