FEATURE: add tree view into creating new category

This commit is contained in:
Michal Kváček
2016-08-11 00:49:05 +02:00
parent 48d301330f
commit 597d161a38
3 changed files with 12 additions and 3 deletions
@@ -17,7 +17,8 @@ class CreateNewCategory extends Controller
public function getNew() public function getNew()
{ {
$category = new Category(); $category = new Category();
$categories = Category::getTree(); $categories = Category::getTree()->toArray();
$modules = Module::where('enabled', true) $modules = Module::where('enabled', true)
->get(); ->get();
@@ -35,8 +35,7 @@
<select name="parentCategory"> <select name="parentCategory">
<option value=""> ---</option> <option value=""> ---</option>
@foreach($categories as $parentCategory) @foreach($categories as $parentCategory)
<option @if($parentCategory->id == $category->parent_id) selected @include('categories::admin.snippets.optionParentCategories', ['level' => 0, 'selectedCategory' => $category, 'currentCategory' => $parentCategory])
@endif value="{{$parentCategory->id}}">{{$parentCategory->name}}</option>
@endforeach @endforeach
</select> </select>
</label> </label>
@@ -0,0 +1,9 @@
<option @if($currentCategory['id'] == $selectedCategory->parent_id) selected @endif value="{{$currentCategory['id']}}">
{{str_repeat('-', $level)}} {{$currentCategory['name']}}
</option>
@if(isset($currentCategory['children']))
@foreach($currentCategory['children'] as $category)
@include('categories::admin.snippets.optionParentCategories', ['selectedCategory' => $selectedCategory, 'currentCategory' => $category, 'level' => $level+1])
@endforeach
@endif