我正在尝试编写某个查询,但我没有使用它,我正在寻求帮助
这就是我想要做的事情
这是我现在拥有的。我已经尝试了很多次,但我无法找出正确的“WHERE”案例选择所有项目 created_at 来自本月之前(7月,6月,...),和 还选择前3个这是在本月创建的
$offertes = DB::table('offertes')
->select('*')
->where('receiver_id', $user_id)
...
->orderby('seen')
->orderby('created_at','desc')
->get();
答案 0 :(得分:0)
这样的事情应该有效:
$time = new Carbon\Carbon('first day of this month'); // Get first day of the month.
$time->setTime(0, 0, 0); // Set time to 00:00:00.
....
->where('created_at', '<', $time)
->where(function($q) {
$q->where('created_at', '>', $time)
->orderby('created_at','asc')
->take(3)
})
->get;