ORM for mysql now() - Laravel 4


ORM for mysql now() - Laravel 4

我有以下sql

select * from bids where deleted_at is  null 
and  publication_date <= now() and open_date >= now()   

我想用ORM

来写
   $bids = Bid::where('publication_date','<=','now()')->where('open_date','>=','now()')->get();

它不工作,然后我重写如下

$bids=DB::select(DB::raw('select * from bids where deleted_at is  null and  publication_date <= now() and open_date >= now()'));

如何在ORM上编写以上查询,我认为now()有问题

您可以使用whereRaw方法:

$bids = Bid::whereRaw('publication_date <= now() and open_date >= now()')->get();