$populars = DB::table('products')
/* ->select(DB::raw(' JOIN (SELECT product_id, MAX(sales) AS sales FROM offers GROUP BY product_id) ON offers.product_id = products.id ')) */
->select( DB::table('offers')
->join('offers.product_id', '=', 'products.id')
->select('product_id')
->max('sales')
->groupBy('offers.product_id')
->get()
)
->orderBy('offers.sales', 'desc')
->take(20)
->get();
SQLSTATE[42000]: Syntax error or access violation: 1049 Unknown database 'offers' (SQL: select max(`sales`) as aggregate from `offers` inner join `offers`.`product_id` on `=` = `products`.`id`)