function _tagExistInPost($postId, $tagId) { $postTag = PostTag::where('post_id', $postId)->where('tag_id', $tagId)->first(); if ($postTag) { return true; } return false; }
public function destroy($id) { // remove specific post $post = Post::where('post_type', 'post')->where('id', $id)->first(); // remove all post meta PostMeta::where('post_id', $post->id)->delete(); // remove all post tags PostTag::where('post_id', $post->id)->delete(); if ($post && $post->delete()) { return true; } return false; }
public static function saveTags($tags, Post $post, $type) { // Remove all previous post and tag relationships $postTags = PostTag::where('post_id', $post->id)->where('type', $type)->delete(); $tagGroup = explode(',', $tags); if ($tags) { foreach ($tagGroup as $key => $tagName) { $tag = Tag::where('name', $tagName)->first(); // Refrain from insertion if the tag already exists. if (!$tag) { $tag = Tag::create(['name' => $tagName, 'slug' => str_slug($tagName), 'type' => $type]); } // Create new post and tag relationships PostTag::create(['post_id' => $post->id, 'tag_id' => $tag->id, 'type' => $type]); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $tag = Tag::where('id', $id)->first(); if ($tag && $tag->delete()) { // Delete any reference from the PostTag. PostTag::where('tag_id', $id)->delete(); return redirect()->back()->with('message', 'Deleted Successfully.'); } return redirect()->back()->with('message', 'Unable to delete.'); }
function _postCategories(Post $post) { return PostTag::where('post_id', $post->id)->where('type', 'category')->get(); }
private function catPosts($tagId) { return PostTag::where('type', 'category')->where('tag_id', $tagId); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { // Find post $post = Post::where('id', $id)->where('post_type', 'page')->first(); // Save new post $post = Post::savePost($request, $post); // Save new tags PostTag::saveTags($request->get('tags'), $post, 'tag'); return redirect()->back()->withInput(); }