本文整理汇总了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;
}
}
}
示例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;
}
示例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;
}