dounanyin3179 2016-11-19 05:24
浏览 99

基于两列计算的雄辩查询

I have a model called quotation which has both a created_at and a valid_for column.

How can a run one eloquent query so that it returns expired quotations (without manually adding a expired_at column e.g. something like this

$quotations = Quotation::where('created_at', '<', Carbon::now()->addDays($this->valid_for));
  • 写回答

1条回答 默认 最新

  • dongshanjin8947 2016-11-19 06:01
    关注

    You need to apply the logic in the sql.

    $quotations = Quotation::where(\DB::row('DATE_ADD(`created_at`, INTERVAL `valid_for` DAY)', '>=', \DB::row('CURRENT_DATE'))->get();
    

    I assume your valid_for is number of days.

    评论

报告相同问题?