我正在尝试建立一个拍卖网站,并且提供了很多类别。这些类别通过2列彼此链接。第一列是类别的ID,另一列是父类别。
我与父母和那些父母的孩子做了一页。我让孩子与那些孩子的孩子联系在一起(对不起,我知道这很混乱。)。
现在的问题是添加孩子的孩子,我该怎么做?
(https://imgur.com/susT53g.png) “表格布局。”
(https://imgur.com/4a6bwjB.png) “现在在网站上显示的方式。”
类别控制器
public function viewCategories(){
$categories = Categories::with('children')->where('parent', -1)->orderBy('NL_name', 'asc')->get();
return view('frontend.categories', compact('categories'));
}
public function viewSubCategories(){
$subcategories = Categories::with('children_of_children')->where('parent', -1 )->orderBy('NL_name', 'asc')->get();
return view('frontend.subcategories', compact('subcategories'));
}
Categories.model
public function parent() {
return $this->belongsTo(self::class, 'id');
}
public function children() {
return $this->hasMany(self::class, 'parent');
}
Subcategories.blade.php
<div class="row justify-content-center">
<ul class="">
<div class="row">
@foreach ($categories as $parent)
<div class="col">
<div class="row d-flex" style="padding-top: 2em">
<a id="{{ substr($parent->NL_name, 0, 1) }}" class="list-group-item list-group-item-action list-group-item-primary"> {{ $parent->NL_name }}</a>
</div>
@if ($parent->children->count())
<ul class="list-group list-group-horizontal list-group-item mw-auto">
@foreach ($parent->children as $child)
<div>
<a href="">{{ $child->NL_name }}</a>
</div>
@endforeach
</ul>
@endif
</div>
@endforeach
</div>
</ul>
</div>