我的模型类别具有父子关系:
Object.keys(properties).forEach(function(key) {
// console.log("dealing with key ",key,properties[key])
if (uischema[key] == undefined) {
uischema[key] = {}
}
if (properties[key].type == "object") {
console.log(key + " is a lvl2 Object!")
Object.keys(properties[key].properties).forEach(function(key2) {
if (uischema[key][key2] == undefined) {
uischema[key][key2] = {}
}
if (properties[key].properties[key2].type == "object") {
// console.log(key2 + " is a lvl3 Object!",properties[key].properties[key2].properties,uischema[key])
Object.keys(properties[key].properties[key2].properties).forEach(function(key3) {
if (uischema[key][key2][key3] == undefined) {
uischema[key][key2][key3] = {}
}
if (properties[key].properties[key2].properties[key3].type == "object") {
我有具有关联类别的产品模型:
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
public function parent()
{
return $this->belongsTo(self::class, 'parent_id')->withoutGlobalScope('active');
}
public function products()
{
return $this->hasMany(Product::class);
}
在CategoryController中,我有方法show:
public function category()
{
return $this->belongsTo(Category::class);
}
在刀片中,我将产品展示为:
public function show(Category $category)
{
return view('main', compact('category'));
}
如果isset @php $products = isset($category) ? $category->products()->paginate(15) : $products; @endphp
@include('partials.products')
变量,那么我得到产品。但这仅适用于某些类别。如何在此格式表中显示父级和子级标题和产品:
category
现在我有了这个
<table>
<tr>
<th>Name Product</th>
<th> Price </th>
</td>
<tr>
<td colspan=2>Parent Category title of products</td>
</tr>
<tr>
<td>Product of parent category #1</td>
<td>890 $ </td>
</tr>
<tr>
<td colspan=2>Child category title of products</td>
</tr>
<tr>
<td>Product of child category #1</td>
<td>890 $ </td>
</tr>
...
</table>
在<table class="table">
<tr>
<th class="th-1">Name</h2></th>
<th class="th-2">Count <!--<span><i class="fas fa-chevron-up"></i>--></span></th>
<th class="th-3">Price <!--<span><i class="fas fa-chevron-up"></i>--></span></th>
<th class="th-4">Sales <!--<span><i class="fas fa-chevron-up"></i>--></span></th>
<th class="th-5"></th>
</tr>
{{-- {{ dd($products->groupBy('category_id')) }} --}}
@php
$products = isset($category) ? $category->products()->paginate(15) : $products;
@endphp
@include('partials.products')
</table>
中:
partials.products
请帮助解决此问题。