當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。