/** * Scope a query to only include upcoming events. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeFilterUpcoming($query) { return $query->whereDate('events.start_at', '>=', date('Y-m-d')); }
private function filterResultsInTime(Builder &$samplingsQueryBuilder, $request) { if ($request->date) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', $request->date); return true; } if ($request->exists("today")) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->toDateString()); return true; } if ($request->exists("yesterday")) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->subDay()->toDateString()); return true; } if ($request->start) { $samplingsQueryBuilder->whereDate('samplings.created_at', '>=', $request->start); if ($request->end) { $samplingsQueryBuilder->whereDate('samplings.created_at', '<=', $request->end); } return true; } return false; }
public function scopeNotYetPublished(Builder $query) { $now = Carbon::now(); return $query->whereDate('books.published_date', '>', $now); }
private function filterResultsInTime(Builder &$samplingsQueryBuilder, $request, Product $product) { if ($request->date) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', $request->date); return true; } if ($request->exists("today")) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->toDateString()); return true; } if ($request->exists("yesterday")) { $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->subDay()->toDateString()); return true; } if ($request->start) { $samplingsQueryBuilder->whereDate('samplings.created_at', '>=', $request->start); if ($request->end) { $samplingsQueryBuilder->whereDate('samplings.created_at', '<=', $request->end); } return true; } if ($request->timeFilter) { $secondQueryBuilder = clone $samplingsQueryBuilder; $lastSampling = $secondQueryBuilder->take(1)->get(["samplings.created_at"])->first()->created_at->copy(); switch ($request->timeFilter) { case "hour": $lastHour = $lastSampling->subHour()->toDateTimeString(); $samplingsQueryBuilder->where("samplings.created_at", ">", $lastHour); break; case "today": $today = $lastSampling->toDateString(); $samplingsQueryBuilder->whereDate("samplings.created_at", "=", $today); break; case "yesterday": $lastDay = $lastSampling->subDay()->toDateString(); $samplingsQueryBuilder->whereDate("samplings.created_at", "=", $lastDay); break; case "week": $lastWeek = $lastSampling->subWeek()->toDateTimeString(); $samplingsQueryBuilder->where("samplings.created_at", ">", $lastWeek); break; case "month": $lastMonth = $lastSampling->subMonth()->toDateTimeString(); $samplingsQueryBuilder->where("samplings.created_at", ">", $lastMonth); break; case "year": $lastYear = $lastSampling->subYear()->toDateTimeString(); $samplingsQueryBuilder->where("samplings.created_at", ">", $lastYear); break; } return true; } return false; }
public function scopeThisWeek(Builder $q) { $q->whereDate($this->startFieldName(), '>=', Carbon::today()->startOfWeek())->whereDate($this->endFieldName(), '<=', Carbon::today()->endOfWeek()); }