【问题标题】:add conditon on whereNotIn() laravel在 whereNotIn() laravel 上添加条件
【发布时间】:2020-05-20 06:03:28
【问题描述】:

我正在尝试检查预订是否是 b/n 请​​求 check_in 和 check_out 日期。如果是,则排除已预订状态 =1 的预订。


$room->bookings()->where(function ($query) use ($check_in, $check_out, $statusCollect) {
                       $query->where('check_in','<=',$check_out) 
                             ->where('check_out','>=',$check_in)
                       ->whereNotIn('book_status_id', $statusCollect)
 });

但问题是这个查询过滤器都在表内。我如何在 whereNotIn() 中使用 if 语句,或者是否有其他方法。

我需要的是如果 check_in=check_out 然后给我预订表行然后检查 bookstatus,如果它通过了给我行。

我希望我不要让它变得复杂:)。 谢谢

【问题讨论】:

  • 能否请您添加您的表结构和所需结果的示例?

标签: laravel if-statement eloquent laravel-query-builder


【解决方案1】:
//controller
//first get data if data get then update the status 
 $data=$room->bookings()->where(function ($query) use ($check_in, $check_out) {
                       $query->where('check_in','<=',$check_out) 
                             ->where('check_out','>=',$check_in)
                       });
if(!empty($data) && $data!=''){
//you can use your table primary id to update the status
$modelObj=new model_name();
$updateArray=$modelObj->updatedById($data->id[
'book_status_id'=>statusCollect
]);
}

//model
function updatedById($id,$statusCollect){
return $this->where('id',$id)->update($statusCollect);
}

【讨论】:

  • 感谢您的快速回复。我不想更新。我只想在过滤检查之前检查 $check_in 和 $check_out 是 b/n 预订 check_in 和 check_out。是这样吗,然后删除我的 book status_id 为 1 的预订
猜你喜欢
  • 2019-03-19
  • 2016-10-26
  • 1970-01-01
  • 2018-05-24
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
  • 2018-05-17
  • 2016-07-13
相关资源
最近更新 更多