我尝试让我的产品基于类别I've done that
,现在我想要显示不同行(设计事项)中的每个类别,我必须使用take
offset
和{{1} }。那也行。
问题在于对这些结果进行排序。
limit
现在的问题是结果将来自所有类别 而不是分开。
BUT
View::composer('welcome', function ($view) {
$category = DB::table('subcategories')
->join('admin_designs', 'admin_designs.category_id', '=', 'subcategories.category_id')
->join('products', function ($join) {
$join->on('subcategories.id', '=', 'products.subcategory_id');
})->take(1)->get();
$categorytwo = DB::table('subcategories')
->join('admin_designs', 'admin_designs.category_id', '=', 'subcategories.category_id')
->join('products', function ($join) {
$join->on('subcategories.id', '=', 'products.subcategory_id');
})->offset(1)->limit(9)->get();
$view->with('category', $category);
$view->with('categorytwo', $categorytwo);
});
并在刀片中使用,例如:
View::composer('welcome', function ($view) {
$category = DB::table('subcategories')
->join('admin_designs', 'admin_designs.category_id', '=', 'subcategories.category_id')
->join('products', function ($join) {
$join->on('subcategories.id', '=', 'products.subcategory_id');
})->get();
$view->with('category', $category);
});
然后它会根据他们的类别ID分别显示结果 唯一的问题是我无法将结果作为
@foreach($category->groupby('category_id') as $key => $value) @foreach($value as $ki) product title{{$ki->title}}, Category id: {{$key}}, Subcategory id: {{$ki->subcategory_id}}<br> @endforeach @endforeach
发布+->take('1')
。
任何想法?