本文整理汇总了PHP中app\Category::roots方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::roots方法的具体用法?PHP Category::roots怎么用?PHP Category::roots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Category
的用法示例。
在下文中一共展示了Category::roots方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: categories
public function categories()
{
$view = Input::get('view');
if ($view == null) {
return redirect('/admin/categories?view=hierarchy');
}
$levels = ['Main Category', 'Subcategory', 'Post Sub Category'];
$types = ['main-categories', 'sub-categories', 'post-sub-categories'];
$views = ['Hierarchy', 'Type', 'All'];
$cats = Category::roots()->get();
$category = Input::get('category');
$_category = Category::find($category);
if ($view == 'type') {
$type = Input::get('type');
if ($type == null) {
$type = $types[0];
}
// array_keys() = get keys from value
// appends() = add 'get' variables (to url)
$cats = Category::whereDepth(array_keys($types, $type))->paginate(25)->appends(Input::except('page'));
} else {
if ($view == 'all') {
$cats = Category::paginate(25)->appends(Input::except('page'));
}
}
return view('admin.main')->with('category', $_category)->with('cats', $cats)->with('levels', $levels)->with('view', $view)->with('views', $views)->with('types', $types);
// only for 'type' view
}
示例2: run
public function run()
{
// Get the categories subtree of the first root category
$categories = Category::roots()->first()->getDescendantsAndSelf();
// Pretend first ser has logged in
auth()->loginUsingId($i = 1);
// Add a page for each category of the subtree
foreach ($categories as $category) {
Page::create(['name' => "Page {$i}", 'source' => "Content of page {$i}", 'category_id' => $category->id]);
$i++;
}
}
示例3: edit
public function edit(Course $course)
{
$user = $this->user;
$mainCategories = Category::roots()->lists('name', 'id');
$main = [];
$main[0] = 'انتخاب کنید';
foreach ($mainCategories as $key => $value) {
$main[$key] = $value;
}
$subCategoriesQuery = $course->categories();
$subCategories = $subCategoriesQuery->lists('name', 'id');
//dd($subCategories);
$selectedMainCategory = $subCategoriesQuery->getParent()->id;
$tagsQuery = $course->tags();
$tags = $tagsQuery->lists('name', 'name');
$selected = $tagsQuery->lists('name')->toArray();
return view('admin.course.edit', compact('course', 'user', 'tags', 'selected'))->with(['title' => 'ویرایش دوره', 'main' => $main, 'subCategories' => $subCategories, 'selectedMainCategory' => $selectedMainCategory, 'selectedSubCategories' => $subCategoriesQuery->lists('id')->toArray()]);
}
示例4: recursive
public function recursive()
{
$cats = Category::roots()->get();
$supercatset = [];
foreach ($cats as $cat) {
$catset = [];
echo $cat->name . '<br>';
foreach ($cat->children()->get() as $sub) {
$subcatset = [];
echo ' ' . $sub->name . '<br>';
foreach ($sub->children()->get() as $post) {
echo ' ' . $post->name . '<br>';
$subcatset[strtolower($post->name)]['title'] = $post->name;
}
$catset[strtolower($sub->name)]['title'] = $sub->name;
$catset[strtolower($sub->name)]['children'] = $subcatset;
}
$supercatset[strtolower($cat->name)]['title'] = $cat->name;
$supercatset[strtolower($cat->name)]['children'] = $catset;
}
return $supercatset;
}
示例5: getCatSet
public function getCatSet()
{
$roots = Category::roots()->get();
$catset = [];
// complete category set, ready to display
$counter = 0;
foreach ($roots as $cat) {
if ($counter > 11) {
break;
}
$catset[$cat->name]['title'] = $cat->name;
$catset[$cat->name]['id'] = $cat->id;
// $catset[$cat->name]['type'] = 'cat'; // not the solution
// echo '<br>' . $cat->name . '<br>';
$subcats = $cat->children()->get();
$subcatcounter = 0;
$subcatcount = count($subcats);
for ($col = 0; $col < 3; $col++) {
if ($subcatcounter == $subcatcount) {
break;
}
// echo 'col ' . $col . '<br>';
$rowcounter = 0;
$fillmore = true;
$postcatcounter = 0;
$postcats = [];
$postcatcount = 0;
$fillhead = true;
$colarray = [];
while ($fillmore) {
// echo 'filling row ' . $rowcounter;
if ($fillhead) {
// echo ' subcat ' . $subcats[$subcatcounter]->name . '<br>';
$colarray[$rowcounter]['title'] = $subcats[$subcatcounter]->name;
$colarray[$rowcounter]['type'] = "subcat";
$colarray[$rowcounter]['id'] = $subcats[$subcatcounter]->id;
$postcats = $subcats[$subcatcounter]->children()->get();
$postcatcount = count($postcats) - 1;
if ($postcatcount == -1) {
$fillmore = false;
}
$subcatcounter++;
$fillhead = false;
} else {
// echo ' postcat ' . $postcats[$postcatcounter]->name . '<br>';
$colarray[$rowcounter]['title'] = $postcats[$postcatcounter]->name;
$colarray[$rowcounter]['type'] = 'postcat';
$colarray[$rowcounter]['id'] = $postcats[$postcatcounter]->id;
$postcatcounter++;
if ($postcatcounter > $postcatcount) {
$postcatcounter = 0;
break;
}
}
$rowcounter++;
if ($rowcounter > 11) {
$fillmore = false;
}
}
$catset[$cat->name]['children'][$col] = $colarray;
}
$counter++;
}
return $catset;
}