原始 sql 以查询构建器的 whereBetween
Raw sql to query builder for whereBetween
SQL查询:
SELECT a.id, b.employee_id ,b.name as user_name, a.start_from, a.end_to, a.leaving_reason
FROM employee_leaves as a
JOIN users as b on a.user_id = b.id
WHERE (start_from BETWEEN '2021-04-21' AND '2021-04-30')
一切正常,数据如期而至。但是当我转换为 laravel 查询生成器时,这是行不通的。如果有人能帮助我。
查询生成器查询:
$data=DB::table('employee_leaves as a')
->join('users as b', 'a.user_id', '=', 'b.id')
->whereBetween('start_from', array($request->from_date, $request->to_date))
->select('a.*', 'b.name as user_name', 'b.id as user_id', 'b.employee_id')
->get();
改变了这个->whereBetween('start_from', array($request->from_date, $request->to_date))
到这个->whereBetween('start_from', [$request->from_date, $request->to_date])
现在这对我来说工作正常
SQL查询:
SELECT a.id, b.employee_id ,b.name as user_name, a.start_from, a.end_to, a.leaving_reason
FROM employee_leaves as a
JOIN users as b on a.user_id = b.id
WHERE (start_from BETWEEN '2021-04-21' AND '2021-04-30')
一切正常,数据如期而至。但是当我转换为 laravel 查询生成器时,这是行不通的。如果有人能帮助我。
查询生成器查询:
$data=DB::table('employee_leaves as a')
->join('users as b', 'a.user_id', '=', 'b.id')
->whereBetween('start_from', array($request->from_date, $request->to_date))
->select('a.*', 'b.name as user_name', 'b.id as user_id', 'b.employee_id')
->get();
改变了这个->whereBetween('start_from', array($request->from_date, $request->to_date))
到这个->whereBetween('start_from', [$request->from_date, $request->to_date])
现在这对我来说工作正常