public static function saveAll(array $data = null, $productcatID) { $me = new self(); if (($result = $me->isEmpty($data)) != false) { return $result; } $productcat = Productcategory::find($productcatID); $allsavedProducts = $me->mustBeUniqueToProductCategories($productcatID); foreach ($data as $p) { if (in_array($p, $allsavedProducts)) { $data['status'] = 'error'; $data['message'] = $p . ' already exist'; } else { static::Create(array('name' => strtolower(trim(extract_char($p, array('text', 'int')))), 'productcat_id' => $productcat->id, 'brand_id' => $productcat->brand_id)); } } if (!isset($data['status'])) { $data['status'] = 'success'; $data['message'] = 'Saved! successfully'; } return Response::json($data); }
/** * addWhere * * You can add a new WHERE clause with your own operator. * * @access public * @param mixed $element * @param array $values * @param string $operator * @return Where */ public function addWhere($element, array $values, $operator) { if (!$element instanceof Where) { $element = new self($element, $values); } if ($element->isEmpty()) { return $this; } if ($this->isEmpty()) { $this->transmute($element); return $this; } if ($this->hasElement()) { $this->stack = [new self($this->getElement(), $this->values), $element]; $this->element = null; $this->values = []; } else { if ($this->operator == $operator) { $this->stack[] = $element; } else { $this->stack = [self::create()->setStack($this->stack)->setOperator($this->operator), $element]; } } $this->operator = $operator; return $this; }