简体   繁体   中英

how can i store the expired products in laravel 8

#this the code in controller #

public function index()
    {
       
    $expired_product = Product::select('expiry_date')
    ->whereNotNull('expiry_date', "<", Now())->get();
      
    return $expired_product; 
    }

to get expired products, you can use basic where :

 $expired_product = Product::where('expiry_date', "<", Now())->get();

 return $expired_product; 
use Carbon\Carbon;

To get the expired product you can use WhereDate

 public function index()
 {
     $expired_product = Product::select('expiry_date')->WhereDate('expiry_date', '>=', Carbon::now()->format('Y-m-d'))->get();
    
      
     return $expired_product;

}

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