Its not duplicate question. Sorry for such type of starting.
$sum = DB::table('tasklists')->sum('list_weight')->where('task_id','10');
it show me Call to a member function where() on float. I am trying to find out the reason ......
Its not duplicate question. Sorry for such type of starting.
$sum = DB::table('tasklists')->sum('list_weight')->where('task_id','10');
it show me Call to a member function where() on float. I am trying to find out the reason ......
Use sum
after the where
as you need to condition first and take output later.
What happens is when you call a function on DB
which generates a output or query result, The facade runs the query and gets you the output.
So, in your case when you call sum
the query prepared before sum
is get executed and sum
returns the sum of results i.e. float
.
Now, you are trying to access where
method on a float(which is output of the sum
) not on the query itself.
That is why you are getting the error.