在Laravel 5.5中如何在不使用的地方使用? [英] How to use where not between in Laravel 5.5?
本文介绍了在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'
雄辩地是否有人尝试并成功地雄辩地建立了此查询.
我知道我可以使用\DB::select(DB::raw());
并得到我的结果.但是我想使用Laravel雄辩的方法.
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();
推荐答案
$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 ,或者您可以重写关于哪里
https://laravel.com/docs/5.5/queries, or you can rewrite as to wheres
这篇关于在Laravel 5.5中如何在不使用的地方使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文