【问题标题】:how can i store the expired products in laravel 8如何将过期产品存储在 laravel 8 中
【发布时间】:2021-10-05 07:20:41
【问题描述】:

#这是控制器中的代码#

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

【问题讨论】:

  • 嗨,@th tom,你想存储它,还是得到它?
  • 您好!确保您的问题很详细,并且您有一个示例输入输出。

标签: php laravel model-view-controller syntax-error


【解决方案1】:

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

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

 return $expired_product; 

【讨论】:

    【解决方案2】:
    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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      • 2016-10-09
      • 2015-09-23
      • 1970-01-01
      • 2021-12-16
      相关资源
      最近更新 更多