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


PHP Category::children方法代码示例

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


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

示例1: buildOptionTree

 protected function buildOptionTree(Category $category, Product $product = null, $level = 0)
 {
     $string = '';
     for ($i = 0; $i < $level; $i++) {
         $string .= '&mdash; ';
     }
     $selected = '';
     if ($product) {
         $product_categories = $product->categories()->get();
         foreach ($product_categories as $product_category) {
             if ($product_category->id == $category->id) {
                 $selected = ' selected';
                 break;
             }
         }
     }
     $html = '<option value="' . $category->id . '"' . $selected . '>' . $string . $category->name . '</option>';
     $children = $category->children();
     if (count($children) > 0) {
         $level++;
         foreach ($children as $child) {
             $html .= $this->buildOptionTree($child, $product, $level);
         }
     }
     return $html;
 }
开发者ID:Nartub600,项目名称:equilibrium,代码行数:26,代码来源:ProductController.php

示例2: subCategoryStore

 /**
  * Created By Dara on 14/2/2016
  * subCategory store
  */
 public function subCategoryStore(Category $category, Request $request)
 {
     $this->validate($request, ['name' => 'required']);
     $category->children()->create(['name' => $request->input('name')]);
     Flash::success(trans('users.subCategoryCreated'));
     return redirect(route('admin.category.subCategory.index', $category->id));
 }
开发者ID:emadmrz,项目名称:tinker,代码行数:11,代码来源:CategoryController.php

示例3: buildOptionTree

 protected function buildOptionTree(Category $category, Category $editable = null, $level = 0)
 {
     $string = '';
     for ($i = 0; $i < $level; $i++) {
         $string .= '&mdash; ';
     }
     $selected = '';
     if ($editable) {
         $selected = $editable->parent()->id == $category->id ? ' selected' : '';
     }
     $html = '<option value="' . $category->id . '"' . $selected . '>' . $string . $category->name . '</option>';
     if (count($category->children()) > 0) {
         $level++;
         foreach ($category->children() as $child) {
             $html .= $this->buildOptionTree($child, $editable, $level);
         }
     }
     return $html;
 }
开发者ID:Nartub600,项目名称:equilibrium,代码行数:19,代码来源:CategoryController.php


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