public function slug($name, $table = '')
 {
     switch ($table) {
         case 'taxonomy':
             $slug = Str::slug($name);
             $obj = new Taxonomy();
             $i = 0;
             while (1) {
                 if ($i == 0) {
                     $check = $obj->where('alias', '=', $slug)->count();
                 } else {
                     $check = $obj->where('alias', '=', $slug . '-' . $i)->count();
                 }
                 if ($check == 0 && $i != 0) {
                     return $slug . '-' . $i;
                 } elseif ($check == 0 && $i == 0) {
                     return $slug;
                 }
                 $i++;
             }
             break;
         case 'post':
             $slug = Str::slug($name);
             $obj = new Posts();
             $i = 0;
             while (1) {
                 if ($i == 0) {
                     $check = $obj->where('alias', '=', $slug)->count();
                 } else {
                     $check = $obj->where('alias', '=', $slug . '-' . $i)->count();
                 }
                 if ($check == 0 && $i != 0) {
                     return $slug . '-' . $i;
                 } elseif ($check == 0 && $i == 0) {
                     return $slug;
                 }
                 $i++;
             }
             break;
         default:
             $slug = Str::slug($name);
             break;
     }
     return $slug;
 }
 public function taxonomyitem(Request $request, $id)
 {
     $limit = 500;
     $request = $request->all();
     $objTaxonomy = new Taxonomy();
     $vocabulary = $objTaxonomy->where('id', '=', $id)->first();
     $page = isset($request['page']) ? $request['page'] : 1;
     $order = isset($request['order']) ? $request['order'] : 'asc';
     $sort = isset($request['sort']) ? $request['sort'] : '';
     $start = $page * $limit - $limit;
     $objTaxonomyitem = new Taxonomyitem();
     $query = $objTaxonomyitem->where('vid', '=', $id);
     if (isset($request['name'])) {
         $query = $query->where('name', 'like', '%' . $request['name'] . '%');
     }
     $paging = $objTaxonomyitem->paginate($limit);
     switch ($sort) {
         case 'name':
             $query = $query->orderBy('name', $order);
             break;
     }
     $list = $query->skip($start)->take($limit)->get();
     //pr($list);die;
     $listdatas = array();
     foreach ($list as $k => $v) {
         $tmp['id'] = $v['id'];
         $tmp['name'] = $v['name'];
         $tmp['parent'] = $v['parent'];
         $listdatas[$k] = $tmp;
     }
     $html = '';
     $tree = array();
     $listdatas1 = $listdatas;
     $listree = $this->listtree($listdatas1, 0, $tree);
     return view('taxonomy::list_item', array('paging' => $paging, 'vocabulary' => $vocabulary, 'listree' => $listree, 'listdata' => $listree, 'items' => $this->printlist($listdatas, 0, $html), 'start' => $start, 'request' => $request, 'vid' => $id));
 }