Exemple #1
0
 /**
  * Get models by date.
  *
  * @param   QueryBuilder  $query
  * @param   int           $year
  * @param   int           $month
  * @param   int           $day
  * @return  QueryBuilder
  */
 public function scopeDate($query, $year, $month = null, $day = null)
 {
     if (!$year) {
         // Unknown year
         $query->whereNull('begins_at');
     } else {
         if ($month === 0 || $month === '0') {
             // Unknown month
             $query->where('begins_at', Carbon::create($year, 1, 1, 0, 0, 0));
         } else {
             $from = Carbon::create($year, $month ?: 1, $day ?: 1)->startOfDay();
             if ($day) {
                 $to = $from->copy()->addDay();
             } else {
                 if ($month) {
                     $to = $from->copy()->addMonth();
                 } else {
                     $to = $from->copy()->addYear();
                 }
             }
             $query->whereBetween('begins_at', [$from, $to->subSecond()])->orderBy(Db::raw("DATE_TRUNC('day', begins_at)"), 'ASC', 'ASC');
         }
     }
     return $query->orderBy('name', 'ASC');
 }
Exemple #2
0
 /**
  * Add a "where null" clause to the query.
  *
  * @param string $column
  * @param string $boolean
  * @param bool $not
  * @return $this 
  * @static 
  */
 public static function whereNull($column, $boolean = 'and', $not = false)
 {
     //Method inherited from \Illuminate\Database\Query\Builder
     return \October\Rain\Database\QueryBuilder::whereNull($column, $boolean, $not);
 }