当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::progeny方法代码示例

本文整理汇总了PHP中app\Category::progeny方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::progeny方法的具体用法?PHP Category::progeny怎么用?PHP Category::progeny使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Category的用法示例。


在下文中一共展示了Category::progeny方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: scopeRefine

 public function scopeRefine($query, $filters)
 {
     foreach ($filters as $key => $value) {
         switch ($key) {
             case 'category':
                 $children = \Cache::remember('progeny_of_' . $value, 15, function () use($value) {
                     Category::progeny($value, $children, ['id']);
                     return $children;
                 });
                 $children[] = ["id" => $value * 1];
                 $query->whereIn('category_id', $children);
                 break;
             case 'conditions':
                 $query->where('condition', 'LIKE', $value);
                 break;
             case 'brands':
                 $query->where('brand', 'LIKE', $value);
                 break;
             case 'min':
             case 'max':
                 $min = array_key_exists('min', $filters) ? trim($filters['min']) != '' ? $filters['min'] : '' : '';
                 $max = array_key_exists('max', $filters) ? trim($filters['max']) != '' ? $filters['max'] : '' : '';
                 if ($min != '' && $max != '') {
                     $query->whereBetween('price', [$min, $max]);
                 } elseif ($min == '' && $max != '') {
                     $query->where('price', '<=', $max);
                 } elseif ($min != '' && $max == '') {
                     $query->where('price', '>=', $min);
                 }
                 break;
             default:
                 if ($key != 'category_name' && $key != 'search' && $key != 'page') {
                     //changing url encoded character by the real ones
                     $value = urldecode($value);
                     //applying filter to json field
                     $query->whereRaw("features LIKE '%\"" . $key . "\":%\"%" . str_replace('/', '%', $value) . "%\"%'");
                 }
                 break;
         }
     }
 }
开发者ID:WebtoolsWendland,项目名称:antVel,代码行数:41,代码来源:Product.php

示例2: progeny

 /**
  * $id category to searh progeny , $list array to use, $fields that you need
  */
 public static function progeny($id, &$list, $fields = ['id', 'name'])
 {
     $childs = Category::childsOf($id)->select($fields)->get();
     if (is_null($childs)) {
         return;
     }
     foreach ($childs as $value) {
         $list[] = $value->toArray();
         Category::progeny($value->id, $list, $fields);
     }
     return;
 }
开发者ID:rolka,项目名称:antVel,代码行数:15,代码来源:Category.php

示例3: countingProductsByCategory

 /**
  * countingProductsByCategory
  * Products total by category collection
  * @param  [type] $all_products refine products
  * @param  [type] $categories   refine categories
  * @return [array] filter used in the product list view menu
  */
 public static function countingProductsByCategory($all_products, $categories)
 {
     $filters = ['category' => []];
     foreach ($categories as $value) {
         $category_id = $value['id'];
         $childs = \Cache::remember('progeny_of_' . $category_id, 15, function () use($category_id) {
             Category::progeny($category_id, $childs, ['id']);
             return $childs;
         });
         $all = $childs;
         $childs = [];
         foreach ((array) $all as $val) {
             $childs[] = $val['id'];
         }
         $qty = 0;
         if ($all_products) {
             $qty = $all_products->where('category_id', $category_id)->count();
             $qty += $all_products->filter(function ($item) use($childs) {
                 return in_array($item->category_id, $childs);
             })->count();
         }
         if ($qty) {
             $filters['category'][$category_id]['id'] = $category_id;
             $filters['category'][$category_id]['name'] = $value['name'];
             $filters['category'][$category_id]['qty'] = $qty;
         }
     }
     //Order by qty
     if (isset($filters['category'])) {
         $filters['category'] = collect($filters['category'])->sortByDesc('qty');
     }
     return $filters;
 }
开发者ID:rolka,项目名称:antVel,代码行数:40,代码来源:productsHelper.php


注:本文中的app\Category::progeny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。