I'm trying to pull values from two columns based from an id. I have the following data in MySQL:
id | Rental | Rentals_Out
1 11 11
I want to add both of those two columns in id 1. I've tried searching here and Google, but I haven't quite found what I'm looking for.
Below is the code I'm using
$sum_column = DB::select("SELECT SUM(Rental + Rentals_Out) as total_gowns FROM tbl_products WHERE id = '1'");
Or I don't mind using Eloquent but how do I enter multiple columns under pluck function? It seems to only work for one column, and I don't want to duplicate the code.
$sum_column = UCPost::where('id', 1)->pluck('Rental')->sum();
The code works under the raw SQL statement, but the output comes out as the following:
[{"total_gowns ":"22"}]
How do I get just the value i.e. 22?