1

I have two columns in a table called expired(boolean) and expire_date(timestamp). I m running a scheduler to check if a coupon is expired or not in everyMinute() while updating the expired column values using foreach, I have found that its changing the expired_date column value with todays date. I found this weird or may be I am messing up with the pass by reference thing.. here is the code

$schedule->call(function () {
            CoursePromotion::where('expired',0)
                ->whereDate('expire_date','<',Carbon::today())
                ->update(['expired' => 1]);
      })->everyMinute();

here is the result,

DB before updating

enter image description here

DB after running the php artisan schedule:run command

enter image description here

Can anyone tell me why the expired_date has been updated with todays date?

Noob Coder
  • 2,816
  • 8
  • 36
  • 61
  • Use `Carbon::now()`, not `Carbon::today()`, the second one just return the date and not the actual time – jeanj Dec 15 '16 at 08:25

1 Answers1

2

Check you database table(Having this 'expired_date' column), not sure but issue with attribute for same column. If you found attribute like 'on update CURRENT_TIMESTAMP' for 'expired_date' column then remove it and check.

enter image description here

Further this 'on update CURRENT_TIMESTAMP' attribute will update date with current on while update action perform for particular record(s).

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57