laravel选择模型groupby,但不包含组可为空的值

7rfyedvj  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(375)

我有一个模型产品。表中有id、description、barcode、sizebarcode和price列。sizebarcode列有一些值和可为空的值。我想选择所有产品和groupby sizebarcode。但它的组将所有可为null的值都归为一。我想省略可为null的值。
我想在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');
}

我的table
我想要的结果,只有绿色值
table

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题