/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $element = Element::find($id); $element->elementLabel = $request->elementLabel; $element->elementColor = $request->elementColor; $element->elementImage = $request->elementImage; $element->save(); return \Redirect::route('element.index'); }
public function saveBook() { $book = Input::get('book'); $chapters = Input::get('chapters'); $bookMdl = Book::find($book['id']); $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']); $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name'])); $bookMdl->save(); foreach ($chapters as $key => $chapter) { if ($chapter['id']) { $chapMdl = Chapter::find($chapter['id']); } else { $chapMdl = new Chapter(); } if ($chapter['id'] && $chapter['isDeleted']) { $chapMdl->delete(); } else { $chapMdl->book_id = $chapter['book_id']; $chapMdl->title = $chapter['title']; $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null; $chapMdl->order = $chapter['order']; $chapMdl->save(); if (count($chapter['elements'])) { foreach ($chapter['elements'] as $key => $element) { if ($element['id']) { $elementMdl = Element::find($element['id']); } else { $elementMdl = new Element(); } if ($element['id'] && $element['isDeleted']) { $elementMdl->delete(); } else { $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id']; $elementMdl->order = $element['order']; $elementMdl->type = $element['type']; if ($element['type'] == 4 || $element['type'] == 5) { $elementMdl->content = json_encode($element['content']); } else { $elementMdl->content = $element['content']; } $elementMdl->note = $element['note']; $elementMdl->save(); } } } } } echo json_encode(['ok']); }
/** * Return a link by text or class name. * * @param Element $parent * Element object to search. * @param string $link * Link text, CSS class, or CSS Id to look for. */ public function findLink($parent, $link) { $element = $parent->findLink($link); if (!$element) { $element = $parent->find('xpath', "//a[@class='{$link}']"); if (!$element) { $element = $parent->find('xpath', "//a[@id='{$link}']"); } } if ($element) { $this->initVars(); $this->vars['link-text'] = $element->getText(); } return $element; }