public function getCategoryDetails($cat_id)
 {
     $category_details = array();
     $cat_details = ProductCategory::select('category_name', 'parent_category_id', 'id')->whereRaw('id = ?', array($cat_id))->first();
     if (count($cat_details) > 0) {
         $cat_details['full_parent_category_name'] = $this->getParentCategoryName($cat_details['id']);
         $category_details = $cat_details;
     }
     return $category_details;
 }
 public function listProductCategory()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $start = Input::has('start') ? (int) Input::get('start') : 0;
     $length = Input::has('length') ? Input::get('length') : 10;
     $search = Input::has('search') ? Input::get('search') : [];
     $productCategories = ProductCategory::select('categories.id', 'categories.name', 'categories.menu_id', 'categories.active', 'parent.name as parent_name')->leftJoin('categories as parent', 'categories.parent_id', '=', 'parent.id')->with('images');
     if (!empty($search)) {
         foreach ($search as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             if ($key == 'active' || $key == 'on_menu') {
                 if ($value == 'yes') {
                     $value = 1;
                 } else {
                     $value = 0;
                 }
                 if ($key == 'active') {
                     $productCategories->where('categories.' . $key, $value);
                 } else {
                     $productCategories->where('categories.menu_id', '>', 0);
                 }
             } else {
                 if ($key == 'parent_id') {
                     $productCategories->where('categories.' . $key, (int) $value);
                 } else {
                     $value = ltrim(rtrim($value));
                     $productCategories->where('categories.' . $key, 'like', '%' . $value . '%');
                 }
             }
         }
     }
     $order = Input::has('order') ? Input::get('order') : [];
     if (!empty($order)) {
         $columns = Input::has('columns') ? Input::get('columns') : [];
         foreach ($order as $value) {
             $column = $value['column'];
             if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                 continue;
             }
             $productCategories->orderBy('categories.' . $columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
         }
     }
     $count = $productCategories->count();
     if ($length > 0) {
         $productCategories = $productCategories->skip($start)->take($length);
     }
     $arrProductCategories = $productCategories->get()->toArray();
     $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => ProductCategory::count(), 'recordsFiltered' => $count, 'data' => []];
     if (!empty($arrProductCategories)) {
         foreach ($arrProductCategories as $productCategory) {
             $image = '';
             if (!empty($productCategory['images'])) {
                 $image = reset($productCategory['images']);
                 $image = $image['path'];
             }
             $arrReturn['data'][] = array(++$start, $productCategory['id'], $productCategory['name'], $productCategory['parent_name'], $image, $productCategory['menu_id'] ? 1 : 0, $productCategory['active']);
         }
     }
     $response = Response::json($arrReturn);
     $response->header('Content-Type', 'application/json');
     return $response;
 }