laravel 5.1 eloquent query
我有一个在PMA中可以正常工作的查询,我正在尝试将其转换为Eloquent,但我肯定缺少一些东西。
这里是SQL查询:
1 2 3 4 5 6 7 | 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; |
而hes是我雄辩的查询:
1 2 3 4 5 6 7 8 9 10 | $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个日期,然后按提交按钮以根据选择的日期获得结果。
此处正常运行的查询没有错误,但没有结果
1 2 3 4 5 6 7 8 9 10 11 | $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(); |
您正在使用
您没有提供有关输入的详细信息。假设输入包含一个名为" field"的字段,则应使用
您似乎想要的不是
1 2 | // the column 'votes' value should be between 1 and 100 $users = DB::table('users')->whereBetween('votes', [1, 100]); |
您似乎想要确保输入值在两个不同的列值之间。您可以通过两个独立的条件来做到这一点:
1 2 | ->where('ppr_children_absence.start', '<', $input['value']) ->where('ppr_children_absence.stop', '>', $input['value']) |
这将确保