我使用的是Query Builder,这是我在Laravel5 中的代码
$users = DB::table('brand_customers')
->select('brand_id')
->where('mobile', $mobile)
->take(15)
->get();
我限制在15条记录,但我也在寻找总数。目前,我正在使用此进行计数。
$users->count();
我尝试了上面的代码,但没有成功。如何使用同一查询同时获取数据和计数。谢谢
使用两个独立的语句,如:
$users = DB::table('brand_customers')
->select('brand_id')
->where('mobile', $mobile);
$count = $users->count();
$users = $users->take(15)->get();