Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

$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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...