Laravel - 高级碳日期查询
Laravel - Advanced Carbon Date Query
我正在尝试编写某个查询,但失败了,我正在寻求帮助
这是我想要做的
SELECT all items WHERE created_at is from before this month (July, June,...), and also select the first 3 which are created during this month
这是我目前拥有的。我已经尝试了很多次,但我无法找出正确的 "WHERE" 案例
$offertes = DB::table('offertes')
->select('*')
->where('receiver_id', $user_id)
...
->orderby('seen')
->orderby('created_at','desc')
->get();
像这样的东西应该可以工作:
$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;
我正在尝试编写某个查询,但失败了,我正在寻求帮助
这是我想要做的
SELECT all items WHERE created_at is from before this month (July, June,...), and also select the first 3 which are created during this month
这是我目前拥有的。我已经尝试了很多次,但我无法找出正确的 "WHERE" 案例
$offertes = DB::table('offertes')
->select('*')
->where('receiver_id', $user_id)
...
->orderby('seen')
->orderby('created_at','desc')
->get();
像这样的东西应该可以工作:
$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;