Laravel Group By / Order By

Job ID: 34661641

Budget: $10 – $30 CAD

\App\Product::selectRaw('id, ROUND((LENGTH(product_unique_id)-LENGTH(REPLACE(product_unique_id, "-", "")))/LENGTH("-")+1) as co, product_unique_id, template_id')
->where('status',1)
->groupBy('template_id')
->whereRaw($whereSku)
->limit(50)
->orderBy('co','ASC')
->get();

I want to get the lowest co item from the group
Related categories: PHP MySQL Laravel