我正在使用Query Builder,这是我在Laravel5中的代码
$users = DB::table('brand_customers')
->select('brand_id')
->where('mobile', $mobile)
->take(15)
->get();
我限制在15条记录中,但我也在寻找总数。目前,我正在计算这个。
$users->count();
我尝试了上面的代码,但没有运气。如何使用相同的查询获取数据和计数。感谢。
答案 0 :(得分:0)
使用两个单独的陈述,如:
$users = DB::table('brand_customers')
->select('brand_id')
->where('mobile', $mobile);
$count = $users->count();
$users = $users->take(15)->get();