Laravel - 高级碳日期查询

时间:2016-08-07 09:34:37

标签: php mysql laravel php-carbon

我正在尝试编写某个查询,但我没有使用它,我正在寻求帮助

这就是我想要做的事情

  

选择所有项目 created_at 来自本月之前(7月,6月,...), 选择前3个这是在本月创建的

这是我现在拥有的。我已经尝试了很多次,但我无法找出正确的“WHERE”案例

   $offertes = DB::table('offertes')
      ->select('*')
      ->where('receiver_id', $user_id)
...
      ->orderby('seen')
      ->orderby('created_at','desc')
      ->get();

1 个答案:

答案 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;