将查询从laravel eloquent转换为原始sql

yr9zkbsy  于 2021-06-16  发布在  Mysql
关注(0)|答案(1)|浏览(399)

有人能帮我把这个有说服力的查询转换成sql查询吗,因为我正在研究这段代码。我很难理解这段代码是什么,因为我是一个新的口才,但我有一些sql的经验。

$checkInDate = date("d-m-Y", strtotime($request->start_date));
$checkOutDate = date("d-m-Y", strtotime($request->end_date));

$availableRooms = $this->_availablerooms->from('availableRoom as r')
    ->selectRaw('*,r.roomDoorNum, r.isAvailable, rt.title as roomType,res.roomReservedID')
    ->join('roomtype as rt','rt.roomTypeID','=','r.roomTypeID')
    ->leftjoin('roomReserved as rr','rr.roomID','=','r.roomID')
    ->leftjoin('reservation as res','res.roomReservedID','=', DB::raw('rr.roomReservedID AND (res.reservationDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate". ' OR res.expiryDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate".')' ))
    ->get();

return $availableRooms;
jdg4fx2g

jdg4fx2g1#

没人真的能帮你。明天,您可能需要一些其他查询来进入和探索。所以我的建议是安装https://github.com/barryvdh/laravel-debugbar 这个包和它将负责将雄辩的查询转换为原始查询。

相关问题