Home > Blockchain >  how can i store the expired products in laravel 8
how can i store the expired products in laravel 8

Time:10-05

#this the code in controller #

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

CodePudding user response:

to get expired products, you can use basic where:

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

 return $expired_product; 

CodePudding user response:

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;

}
  • Related