【发布时间】:2015-09-26 21:48:09
【问题描述】:
我有一个在 PMA 中运行良好的查询,我正在尝试将其转换为 Eloquent,但我一定遗漏了一些东西。 这里是 SQL 查询:
SELECT t1.* FROM ppr__child_absence t1
LEFT JOIN ppr__children t3 ON t3.idcode=t1.child_idcode
WHERE t1.id = (SELECT t2.id FROM ppr__child_absence t2
WHERE t2.child_idcode = t1.child_idcode
ORDER BY t2.id DESC LIMIT 1)
AND t3.deleted_at IS NULL
AND $input BETWEEN start AND stop;
他是我雄辩的疑问:
$input = Request::all();
$pprs =
DB::table('ppr__child_absence')
->join('ppr__children', function($join) {
$join->on('ppr__children.idcode', '=', 'ppr_children_absence.child_idcode')
->where('ppr__child_absence.child_idcode', '=', DB::raw('SELECT t2.id FROM ppr__child_absence t2
WHERE t2.child_idcode = ppr__child_absence.child_idcode
ORDER BY t2.id DESC LIMIT 1'));})
->whereNull('ppr__children.deleted_at')
->whereBetween($input, array('ppr_children_absence.start','ppr_children_absence.stop'))->get();
我不断收到错误: Grammar.php 第 58 行中的 ErrorException: strtolower() 期望参数 1 是字符串,给定数组。
这里有人能引导我走向正确的方向吗? 基本上用户有 1 个日期输入,带有日期选择器和提交按钮,以根据选择的日期获取结果。
在此处进行查询,没有错误但没有结果
$input = Request::all();
$pprs = DB::table('ppr__child_absence')
->select('ppr__child_absence.*')
->join('ppr__children', function($join) {
$join->on('ppr__children.idcode', '=', 'ppr__child_absence.child_idcode')
->where('ppr__child_absence.id', '=', DB::raw('SELECT t2.id FROM ppr__child_absence t2
WHERE t2.child_idcode = ppr__child_absence.child_idcode
ORDER BY t2.id DESC LIMIT 1'));})
->whereNull('ppr__children.deleted_at')
->where('ppr__child_absence.start', '<', $input['ppr_day'])
->where('ppr__child_absence.stop', '>', $input['ppr_day'])->get();
【问题讨论】:
标签: php mysql laravel eloquent