if you want to use $sales->total_sales with that, you'd need to replace get() with first()
$sales = DB::table('order_lines')
->select(DB::raw('sum(quantity*per_qty) AS total_sales'))
->where('product_id', '=', $product->id)
->first();
it's just that eloquent always returns results in a collection. there's also firstOrFail(), in case you could possibly return no row.
Thanks! Is there a way to just return the sum? This seems to do that and not a collection (but I can't combine columns)?
$total_sales = OrderLine::where('product_id', '=', $product->id)->sum('quantity');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community