我正在嘗試使用 Laravel 查詢生成器重寫 MYSQL 查詢
所以這是查詢
DB::select("SELECT * FROM accomodation WHERE id NOT IN
(SELECT accomodation_id FROM bookings
WHERE (`checkin` <= '$request->in' AND `checkout` >= '$request->out'));");
這就是我到目前為止所做的
Accommodation::whereNotIN('id', function($q)
{
$q->select('accomodation_id')
->from('bookings')
->where('checkin', '<=', '$request->out')
->where ('checkout', '>=', '$request->in');
})
->get();
問題是第一個查詢給了我預期的結果,但第二個沒有
有人可以指出我做錯了什么嗎?
uj5u.com熱心網友回復:
我覺得你打錯了。看$request->in和$request->out。你可能想翻轉它。以及為什么使用'$request->in'而不是$request->in. 它將決議為字串而不是值
uj5u.com熱心網友回復:
你沒有use。例如php Accommodation::whereNotIN('id', function($q) use ($request),您需要使用請求翻轉條件;)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/452471.html
