@tchopa when I test it I got the result. Are you sure you have gross_value for 'Buy' transaction_type? You can also do with where clause
Transaction::where('transaction_type', 'Buy')->sum('gross_value');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all.
Trying to filter some data for a query, below is currently what I'm using to filter out data that only has the transaction_type of 'Buy'
$total_sales = DB::table('transactions')
->whereRaw("transactions.transaction_type = 'Buy' ")
->sum('transactions.gross_value');
However whenever I dd the variable, I get zero.
Is my syntax for the whereRaw statement incorrect? The column transaction_type contains either Buy or Sell, so I just want to select the rows that have Buy.
Thanks in advance
@tchopa when I test it I got the result. Are you sure you have gross_value for 'Buy' transaction_type? You can also do with where clause
Transaction::where('transaction_type', 'Buy')->sum('gross_value');
Please or to participate in this conversation.