简体   繁体   中英

how to give condition for matching expiry_date is greater than & equal to current date(laravel)

i want to fetch data from database based on condition as 'expires_on' should be '>=' 'current_date'. this is my code:

    $date = new Carbon;
    $news = DB::table('feed_news')
            ->select('*')
            ->where('expires_on', '>=' ,$date)
            ->orderBy('news_date','DESC')
            ->get(); 

my problem is :

when i do dd($news), it returns me all data based on expires_on '>' current_date but not equal to current_date.

Use the whereDate() method:

DB::table('feed_news')->whereDate('expires_on', '>=', $date->toDateString())
    ->latest('news_date')
    ->get(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM