/** * 判断pos是否已经被用 * @param $pos * @return bool */ protected function checkPos($pos) { $layout = ShopIndexLayout::whereRaw("pos=:pos", array(":pos" => $pos))->first(); if ($layout instanceof ShopIndexLayout) { return false; } return true; }
/** * 保存数据 * @return \Illuminate\View\View * @throws DeepInHtmlException */ public function save() { $pos = intval(\Input::get("pos")); // if ($this->checkPos($pos) == false) { // throw new DeepInHtmlException("pos:{$pos}已经存在~!"); // } $itemType = intval(\Input::get("itemtype")); $itemId = intval(\Input::get("itemid")); $id = intval(\Input::get("id")); $layout = null; if ($id > 0) { try { $layout = $this->find($id); } catch (DeepInException $e) { throw new DeepInHtmlException($e->getMessage()); } } if (!$layout instanceof ShopIndexLayout) { $layout = new ShopIndexLayout(); } $layout->pos($pos); $layout->itemType($itemType); $layout->itemId($itemId); if ($layout->save() == false) { throw new DeepInHtmlException("保存失败~!"); } return $this->success("保存成功~!"); }