@starmatt
Did you add last_cart_timestamp to the dates array on your model?
https://laravel.com/docs/master/eloquent-mutators#date-mutators
However, I would change this a little, and do something like (untested code).
$schedule->call(function() {
$olderThan = \Carbon\Carbon::now()->subMinutes(30);
$users = User::where('last_cart_timestamp', '<', $olderThan->format('Y-m-d H:i:s'))->get();
foreach($users as $user) {
CartController::getEmpty($user->id);
$user->last_cart_timestamp = null;
$user->save();
}
})->everyMinute();
so we use the DB to look up and find the users, instead of getting all of them and filtering in PHP. Make sure last_cart_timestamp is indexed.
However I still don't like the code.
CartController::getEmpty($user_id);
I don't think this should be a controller function. I would rather see a Cart object which this gets called on.
I would also move
$olderThan = \Carbon\Carbon::now()->subMinutes(30);
$users = User::where('last_cart_timestamp', '<', $olderThan->format('Y-m-d H:i:s'))->get();
out to a method as well (maybe a query scope on the user. User::getOldSessions().
I would also change it from being every minute to every 5 or 10 that it checks...
Lastly... is 30 minutes to short? I add some stuff to the cart, then go and make a coffee and get my CC before making the purchase and then it's timed out (how long is too long?...).
Good luck.