Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

php - How to use where not between in Laravel 5.5?

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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...