We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Example: Get the number of rows along with the total value of the percent field
$result = UserActivity::select(function($s){ $s->sum('percent')->as('sum'); $s->count()->as('count'); }) ->where('client_id', $client->id) ->first();
SELECT SUM(`percent` as 'sum'), count(*) as 'count' WHERE `client_id` = :client_id
Output:
{"sum": 160, "count": 3}
Examples for creating more complex and nested conditions
DB::table('messages')->where('credit', '<', 0) ->where(function($w){ $w->where(function($s){ $s->where('from_user_id',$user_a_id)->or('to_user_id', $user_b_id); }); $w->or(function($s){ $s->where('from_user_id',$user_a_id)->or('to_user_id', $user_b_id); }); })
SELECT FROM `messages` where `credit` < 0 AND ((`from_user_id` = :user_a_id OR `to_user_id` = :user_b_id) or (`from_user_id` = :user_b_id OR `to_user_id` = :user_a_id))