public function getPostsByTag($tag) { $slug = str_slug($tag, '_'); $key = 'post_tag_' . $slug; if (Cache::has($key)) { return Cache::get($key); } else { $posts = Tags::where('tag', 'like', $tag)->first()->posts()->active()->paginate(10); Cache::put($key, $posts, 5); } return $posts; }
public function getTag($aliasOrId) { $tag = Tags::where('id', $aliasOrId)->orWhere('tag_name', $aliasOrId)->firstOrFail(); $diary = Tags::find($tag->id)->diary()->where('diary.status', 1)->orderBy('created_at', 'desc')->paginate(10); return view('site.diary.diary', ['pageInfo' => ['pageLogo' => 'diary', 'siteTitle' => 'Diary by Tag | ' . $tag->tag_name, 'pageHeading' => 'Diary | ' . $tag->tag_name, 'pageHeadingSlogan' => 'I write here what I learn'], 'data' => $diary]); }
public function getSearch(Request $req) { $query = rawurldecode($req->input('q')); $words = explode(' ', $query); $skipKeywords = ['in', 'are', 'of', 'at', 'a', 'is', 'to', 'an', 'for', 'and', 'or', 'with']; $tags = []; $keywords = array_diff($words, $skipKeywords); $diary = Diary::with('tags')->where(function ($q) use($keywords) { foreach ($keywords as $tag) { $q->orWhere('diary.title', 'like', '%' . $tag . '%'); } })->where('diary.status', 1)->orderBy('title', 'asc')->paginate(10); if (count($diary) < 1) { $tags = Tags::where(function ($q) use($words) { foreach ($words as $word) { $q->orWhere('tag_name', 'like', '%' . $word . '%'); } })->get(['tag_name', 'id']); } return view('site.diary.diary', ['pageInfo' => ['pageLogo' => 'diary', 'siteTitle' => 'Search | ' . $query, 'pageHeading' => 'Search | ' . $query, 'pageHeadingSlogan' => 'Search everything what I write'], 'data' => $diary, 'tags' => $tags]); }
private function _setTags($tags_str, $post_id) { PostTag::where('post_id', $post_id)->delete(); $tags = explode(', ', $tags_str); foreach ($tags as $tag) { if (trim($tag) == '') { continue; } $tag = mb_strtolower($tag); $dbtag = Tags::where('tag', 'like', $tag)->first(); if (empty($dbtag)) { $dbtag = new Tags(); $dbtag->tag = strip_tags($tag); $dbtag->save(); } $post_tag = new PostTag(); $post_tag->post_id = $post_id; $post_tag->tag_id = $dbtag->id; $post_tag->save(); } }
/** * EDITAR TAG || EDIT TAG * * @return Response */ public function editarTag() { $id = \Input::get('tag_id'); $tag = \Input::get('tag_titulo'); if ($id == '' || $tag == '') { return 'campovazio'; } else { $verTags = \App\Models\Tags::where('tag_titulo', $tag)->first(); if (count($verTags) <= 0) { $dados = array('tag_titulo' => $tag, 'tag_slug' => str_slug($tag), 'updated_at' => date('Y-m-d H:i:s')); if (Tags::where('tag_id', $id)->update($dados)) { return 'sucesso'; } else { return 'semodificacao'; } } else { return 'tagexiste'; } } }