【发布时间】:2018-10-01 18:51:23
【问题描述】:
我有一个模型产品。表格中有列 id、description、barcode、sizebarcode、price。 Sizebarcode 列有一些值和可以为空的值。我想对不可为空值的 sizebarcode 列进行分组。空值直接选择,不分组。我想在分组时省略可为空的值。
我想选择 sizebarcode 中的所有唯一值以及所有可以为空的值
控制器.php
$products = Category::where('slug',$slug)->first()->products_front()->paginate(12);
return view('page.shop',compact('products'))
模型.php
public function products_front(){
return $this->hasMany('App\Product','cat_id','id')
->groupBy('sizebarcode')
->orderBy('created_at','asc');
}
【问题讨论】:
-
这段代码做了什么结果?
-
@Goms 我想从表中选择唯一值。但我所有的问题是当我分组时,没有选择可以为空的值