/** * Update a tag in the database. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $tag = Tag::findOrFail($id); $this->validate($request, $this->rules); $tag->title = $request->input('title'); $tag->save(); return redirect()->route('tag.view', ['id' => $tag->id]); }
/** * Show update form. * * @param int $id * * @return Response */ public function edit($id) { $image = Image::with(['tags'])->findOrFail($id); $tags = Tag::orderBy('title', 'asc')->lists('title', 'id'); return view('image/tag/edit', ['pageTitle' => $this->pageTitle([trans('image.tag.edit.page-title', ['title' => $image->title])]), 'image' => $image, 'tags' => $tags]); }
/** * Automatically find tags for the image and assign them. * * @return boolean */ public function autoFindTags() { $url = str_finish(Config::get('services.alchemyapi.url'), '/') . 'URLGetRankedImageKeywords'; $imageUrl = null; $previewSize = $this->getImageSize('preview'); if ($previewSize > 1024 * 1024 || $previewSize === 0) { $imageUrl = $this->thumbnailUrl; } else { $imageUrl = $this->previewUrl; } $params = ['url' => $imageUrl, 'apikey' => Config::get('services.alchemyapi.key'), 'outputMode' => 'json']; $url .= '?' . http_build_query($params); $tags = json_decode(file_get_contents($url)); if (strtolower($tags->status) != 'ok') { Log::error("Unsuccessfull response from tagging api for image #{$this->id}: " . serialize($tags)); return false; } if (count($tags->imageKeywords) === 0) { $tag = Tag::firstOrCreate(['title' => 'unknown']); $this->tags()->attach($tag->id); return true; } foreach ($tags->imageKeywords as $tagRaw) { $tag = Tag::firstOrCreate(['title' => $tagRaw->text]); $this->tags()->attach($tag->id); } return true; }