laravel在query builder中 使用where條件的情況:
如果你想要查詢如下情況的sql語句,那么你來對地方了這兒就是幫你解決問題的。
select * from `wxm_ticket` where `wxm_ticket`.`deleted_at` is null and `user_id` = ? and `sell_status` = ? and (`stop_sell` is null or `stop_sell` >= ?)
想要的php 代碼:
$query = TicketModel::user($admin_id)->sellStatus(1)->where(function($query){ $query->orWhereNull('stop_sell')->orWhere('stop_sell', '>=', \Carbon\Carbon::now()); });;
此處只是拋磚引玉 小舉一例 根據不同的情況大家各自實現 如有問題 可以留言!