我有一個查詢,在PMA中正常工作,我試圖將其轉換爲雄辯,但我必須缺少一些東西。 這裏的SQL查詢:laravel 5.1雄辯查詢
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是我的口才查詢:
$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();
我不斷收到錯誤: ErrorException在Grammar.php線58: 用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();
謝謝!我確實想念那個,但也有別的。我收到錯誤SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'2015-09-26'。它試圖找到一列,並不認爲它是一個日期。即使它在模型文件中聲明。 $輸入字段字段名稱將是'ppr_day'。 – Merrant
還在DB :: table('ppr__child_absence')後添加了一行 - > select('ppr__child_absence。*') – Merrant