【问题标题】:How to pass (start <= date1 and end >= date1) || (start <= date2 and end >= date2) condition in laravel如何通过(开始<=日期和结束>=日期1)|| (start <= date and end >= date2) laravel 中的条件
【发布时间】:2021-04-16 09:33:08
【问题描述】:

大家好,我想通过这样的条件: (开始 = date1) || (start = date2) 在 laravel 中。 如何通过这个查询?

$events = DB::table('christophheich_calendar_entries')->whereNull('deleted_at');

有人可以帮忙吗? 谢谢

【问题讨论】:

标签: laravel eloquent octobercms


【解决方案1】:

您可以使用where 语句,如下所示:

$events = DB::table('christophheich_calendar_entries')
    ->where(function($q) use($date1, $date2) {
        $q->where(function($q2) use($date1) {
            $q2->where('start', '<=', $date1)->where('end', '>=', $date1);
        })->orWhere(function($q2) use($date2) {
            $q2->where('start', '<=', $date2)->where('end', '>=', $date2);
        });
    })
    ->whereNull('deleted_at');

这是创建带有处理 where 的 or 部分的内部查询的 where 子句的方法。确保 $date1$date2 在查询之前被初始化。

【讨论】:

    猜你喜欢
    • 2019-01-13
    • 2022-01-23
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    相关资源
    最近更新 更多