php - How do I use eloquent for TIMEDIFF? -


public function fire() {            log::info('delete abandoned builds.');      $builds = build::where('status', build::status_abandoned)                     ->whereraw (timediff(date_format(now(), '%y-%m-%d %h:%i:%s'), created_at) >= '01:00:00')->get();                         $buildrepository->delete($build);     $buildrepository = new buildrepository();  } 

basically, have delete builds after have been abandoned 1 hour. gives me error timediff undefined. can tell me how can fix this?

you use eloquent , datetime instead of timediff

$date = new datetime; $date->modify('-60 minutes'); $formatted_date = $date->format('y-m-d h:i:s');  db::table('builds')   ->where('status', build::status_abandoned)   ->where('created_at','>=',$formatted_date)   ->delete(); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -