本文整理汇总了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 .= '— ';
}
$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;
}
示例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));
}
示例3: buildOptionTree
protected function buildOptionTree(Category $category, Category $editable = null, $level = 0)
{
$string = '';
for ($i = 0; $i < $level; $i++) {
$string .= '— ';
}
$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;
}