public function category(Request $request) { $lastSegment = preg_split("/\\//", $request->url()); $categorySlug = array_pop($lastSegment); // get the last segment on the current url $category = Tag::where('slug', $categorySlug)->first(); // check if there is no category found. if (!$category) { return redirect()->route('front.error-404'); } // condition where clause for parent categories or child. if ($category->parent_id == 0) { $field = 'tags.parent_id'; $value = $category->id; } else { $field = 'tags.slug'; $value = $category->slug; } // Get posts by PostTag slug or parent_id field $properties = Post::join('post_tags', 'posts.id', '=', 'post_tags.post_id')->join('tags', 'post_tags.tag_id', '=', 'tags.id')->where($field, $value)->select('posts.*', 'tags.name as tagName')->paginate(config('front.postPerPage')); $pageTitle = 'Category: ' . $category->name; if ($category->parent_id == 0) { $breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category') . '/' . $category->slug, 'name' => $category->name]]; } else { $breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category', $category->parent()->slug), 'name' => $category->parent()->name], ['url' => route('front.category') . '/' . $category->parent()->slug . '/' . $category->slug, 'name' => $category->name]]; } return view('properties', compact('properties', 'pageTitle', 'breadcrumbData')); }
/** * 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 _tagCategoryList($tags = array()) { if (!$tags) { $tags = Tag::where('type', 'category')->where('parent_id', '!=', 0)->get(); } $tagList[0] = "Please select"; if (count($tags) > 0) { foreach ($tags as $tag) { if ($tag->type == 'category') { $tagList[$tag->id] = $tag->name; } } } return $tagList; }
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]); } } }
public function subCategories($tagId) { return Tag::where('parent_id', $tagId)->where('type', 'category')->get(); }
<div class="clearfix"></div> <hr> <label for="geocomplete">Location Search</label> <input id="geocomplete" type="text" class="form-control" placeholder="Type in an address" name="meta[geo_location]" value="{{ _postMeta($post->id, 'geo_location') }}"> <input id="find" type="button" class="btn btn-primary" value="Find Address" /> <div class="map_canvas"></div> <hr> <label for="geocomplete">Property Category</label> <div class="panel-group" id="accordion2"> <?php $categoryList = \Xadmin\Models\Tag::where('type', 'category')->where('parent_id', 0)->get(); ?> @forelse( $categoryList as $i => $category) <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#{{ str_slug( $category->name )}}"> {{ $category->name }} </a> </h4> </div> <div id="{{ str_slug( $category->name )}}" class="panel-collapse collapse"> <div class="panel-body"> <div class="row"> <?php $repo = new \Xadmin\Repositories\TagRepo();
public function parent() { return Tag::where('id', $this->parent_id)->first(); }