Laravel Eloquent Join with SUM()

Solution:

DB::query()
    ->select(
        'p.id AS product_id',
        'p.name AS product_name',
    )
    ->selectRaw('SUM(s.quantity) AS product_quantity') // need to use selectRaw for aggregate values like this.
    ->from('products', 'p')
    ->join('stocks as s', 'p.id', 's.product_id')
    ->groupBy('p.id')
    ->get();

Using the syntax in your comment:

$this->model
     ->select("products.id as product_id", "products.name as product_name")
     ->selectRaw("SUM(quantity) as product_quantity") // select() doesn't work for aggregate values
     ->join("products", "products.id", "=", "stocks.product_id")
     ->groupBy("products.id")
     ->get()