Reputation: 1515
Hi everyone I'm using Laravel and I'm trying to get a single value from the database using pluck
,
the issue is the query must be written in the Laravel way not the normal sql.so how to write this
sql query in Laravel ? I want to be able use AS
to change the column name and SUM
.all I want actually is to get the value from total_quantity
column to do that I have to use pluck.
any idea how to write that query ?
Thanks in advance.
$PhysicalStock=DB::select("select sum(quantity) as `total_quantity` from InOutProducts where productID=$productID and InAndOut=1;")->pluck('total_quantity');
Upvotes: 0
Views: 980
Reputation: 3588
Read more about Larvel DB and Eloquent.
DB::table('InOutProducts')->selectRaw('SUM(quantity) as total_quantity')->where('productId', '=', $productID)->where('InAndOut', '=', 1)->pluck('total_quantity');
Upvotes: 1