我如何将过期产品存储在 laravel 8

how can i store the expired products in laravel 8

#这是控制器中的代码#

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

要获取过期产品,您可以使用基本 where:

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

 return $expired_product; 
use Carbon\Carbon;

要获取过期产品,您可以使用 WhereDate

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

}