It seems you are missing the group by clauses. When using an aggregate column you should group your results.
Check this Laracasts video on SQL Aggregates:
https://laracasts.com/series/mysql-database-design/episodes/6
Try this simplified version and see if it works:
Route::get('best', function () {
$products = Product::query()
->join('order_items', 'order_items.productId', '=', 'products.id')
->selectRaw('products.*, SUM(order_items.quantity) AS quantity_sold')
->groupBy(['products.id']) // should group by primary key
->orderByDesc('quantity_sold')
->take(20) // 20 best-selling products
->get();
return $products;
});
Tested locally, with a slightly different DB model, and it worked. You may have to change something to get ir working with your DB structure.
Hope it helps.