Пример #1
0
 /**
  * Scope only data before datetime
  * @param query     $query      Query object
  * @param date      $datetime   End datetime
  * @param int       $offset     Time offset after end datetime
  * @return mixed                New query object
  */
 public function scopeTo($query, $datetime, $offset = 7200)
 {
     if ($datetime) {
         $unix_timestamp = strtotime($datetime) + $offset;
         $date = date('Y-m-d', $unix_timestamp);
         $time = date('H:i:s', $unix_timestamp);
         return $query->whereRaw("\n\t\t\t\t(date < DATE '{$date}'\n\t\t\t\tOR\n\t\t\t\tdate = DATE '{$date}' AND time <= TIME '{$time}')\n\t\t\t");
     }
     return $query;
 }