【问题标题】:How to use where not between in Laravel 5.5?如何在 Laravel 5.5 中使用 where not between?
【发布时间】:2018-08-30 14:23:57
【问题描述】:

我试试 得到这样的东西

select * from `users`
inner join `settings`
    on `users`.`id` = `settings`.`user_id`
    and NOW() NOT BETWEEN quit_hour_start AND quit_hour_end
where `notification_key` != ''
    and `device_type` = 'Android'

雄辩。有没有人尝试并成功地以雄辩的方式构建此查询。 我知道我可以使用\DB::select(DB::raw()); 并得到我的结果。但是我想用 ie 和 Laravel 雄辩的方法。

====== 更新已尝试查询的评论========

$androidUser = User::join('settings', function ($join) {
        $join->on('users.id', '=', 'settings.user_id')
        ->where(DB::raw("'$currentTime' NOT BETWEEN quit_hour_start AND quit_hour_end"));
    })
    ->where('notification_key', '!=', '')
    ->where('device_type' ,'=', 'Android')
    ->get();

【问题讨论】:

  • 您是否尝试过编写任何代码来使用 Eloquent 执行此操作?或者这是一个简单的为我做的
  • 是的,请检查更新的问题

标签: php laravel eloquent laravel-5.5


【解决方案1】:
$users = DB::table('users')
                ->whereNotBetween('votes', [1, 100]) // For one column
                ->whereRaw("? NOT BETWEEN quit_hour_start AND quit_hour_end", [$currentTime]) // Use whereRaw for two columns

                ->get();

https://laravel.com/docs/5.5/queries,或者你可以重写到哪里

【讨论】:

  • 是的,我检查了但需要不同的列(quit_hour_start,quit_hour_end)不在 quit_hour_start 和 quit_hour_end 之间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 2013-10-09
  • 1970-01-01
相关资源
最近更新 更多