Laravel 如何通过查询查找可用日期

Laravel 如何通过查询查找可用日期,laravel,Laravel,你能帮我建立一个查询,在Laravel Eloquent中查找免费日期吗 所以我有两个模型,节点和预订。 模型之间有许多关系 public function dates() { return $this->hasMany(Booking::class, 'object_id', 'nid'); } 预订模式具有以下结构: | bid | object_id | checkin | checkout | | 1 | 32 | 2017-04-25 |

你能帮我建立一个查询,在Laravel Eloquent中查找免费日期吗

所以我有两个模型,节点和预订。 模型之间有许多关系

public function dates()
{
    return $this->hasMany(Booking::class, 'object_id', 'nid');
}
预订模式具有以下结构:

| bid | object_id  | checkin    | checkout   |
|  1  | 32         | 2017-04-25 | 2017-04-28 |
|  2  | 32         | 2017-05-01 | 2017-05-09 |
|  3  | 44         | 2017-04-21 | 2017-04-24 |
|  4  | 51         | 2017-05-01 | 2017-05-08 |
我的目的是查找给定日期之间的可用节点

因此,如果我想搜索一个日期(例如created_at),很简单:

whereBetween(‘created_at’, [$date1, $date2])

但是如何在签入和签出两个日期之间创建搜索查询呢?

你是说这样的

$query->where('checkin','<=', $date)
      ->where('checkout','>=', $date);
$query->where('checkin','=',$date);

您还可以将其添加到范围:

whereRaw([$date1,$date2])