Skip to content

Instantly share code, notes, and snippets.

@pulading1988
Last active July 31, 2017 09:09
Show Gist options
  • Save pulading1988/dc80278d7a84c887baa1d1a20d2cf6ad to your computer and use it in GitHub Desktop.
Save pulading1988/dc80278d7a84c887baa1d1a20d2cf6ad to your computer and use it in GitHub Desktop.
laravel查询参数分组
SELECT *
FROM `market_list`
WHERE `id` IN ('1', '2')
AND `status` = '1'
AND (`start_time` IS NULL
OR `start_time` <= '2017-07-31 17:05:57')
AND (`end_time` IS NULL
OR `end_time` >= '2017-07-31 17:05:57')
ORDER BY `priority` DESC
LIMIT 5
$market = MarketListModel::whereIn('id', $ids)
->where('status', '=', MarketListModel::STATUS_VALID)
->where(function($query) use($now) {
$query->whereNull('start_time')->orWhere('start_time', '<=', $now);
})
->where(function($query) use($now) {
$query->whereNull('end_time')->orWhere('end_time', '>=', $now);
})
->orderBy('priority', 'desc')
->limit(5)
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment