直接從程式碼來看,假設code這樣寫:
$this-customer-select(['id'])
-where('cell_1', '=', $cell_1)
-orWhere(function ($query) use ($cell_2) { $query-whereNotNull('cell_2'); $query-where('cell_2', '=', $cell_2);
})
-orWhere('email', '=', $email)
-get()-first();
轉換成SQL其實就是這樣:
select `id` from `customer` where `cell_1` = ? or (`cell_2` is not null and `cell_2` = ?) or `email` = ?
加入括號其實就是使用閉包的寫法!
本筆記參考:
1. https://www.weiyuan.com.tw/article/25