How to use where not between in Laravel 5.5?

你。 提交于 2019-12-13 10:12:26

问题


I am try ing to get something like this

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'

in eloquent. Does anyone try and get success to build this query in eloquent. I know I can use \DB::select(DB::raw()); and get my result. But I want to use ie with Laravel eloquent method.

====== update comment for tried queries========

$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();

回答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, or you can rewrite as to wheres



来源:https://stackoverflow.com/questions/49406790/how-to-use-where-not-between-in-laravel-5-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!