【发布时间】:2017-05-12 13:22:25
【问题描述】:
我是 Laravel 的新手。
我想知道如何避免查询被链接。
$visitRecords = VisitRecord::whereDate('visited_at', '=', Carbon::today()->toDateString());
$knockBounce = $visitRecords->where("bounce_zone", "1")->get()->count();
$approachBounce = $visitRecords->where("bounce_zone", "2")->get()->count();
这是我编写的代码,但这给了我意想不到的结果......
结果
select * from `visit_records` where date(`visited_at`) = '2017-05-12'
select * from `visit_records` where date(`visited_at`) = '2017-05-12' and `bounce_zone` = '1'
select * from `visit_records` where date(`visited_at`) = '2017-05-12' and `bounce_zone` = '1' and `bounce_zone` = '2'
我检查了进行的查询,这就是我得到的。
我的期望...
select * from `visit_records` where date(`visited_at`) = '2017-05-12'
select * from `visit_records` where date(`visited_at`) = '2017-05-12' and `bounce_zone` = '1'
select * from `visit_records` where date(`visited_at`) = '2017-05-12' and `bounce_zone` = '2'
我想通过 Eloquent 方法执行此查询。
【问题讨论】:
-
检查this - 你确定它是链式的吗?它不应该
-
我从调试栏控制台得到了这些 sql 查询。
标签: php laravel laravel-5 laravel-4