1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\ModelFilters;
- use Carbon\Carbon;
- use EloquentFilter\ModelFilter;
- class ActionFilter extends ModelFilter
- {
- /**
- * Related Models that have ModelFilters as well as the method on the ModelFilter
- * As [relationMethod => [input_key1, input_key2]].
- *
- * @var array
- */
- public $relations = [];
- public function user($id)
- {
- return $this->where("created_by", $id);
- }
- public function time($time)
- {
- return match ($time) {
- "today" => $this->where("created_at", ">=", Carbon::now()->startOfDay()),
- "yesterday" => $this->where("created_at", ">=", Carbon::now()->subDay()->startOfDay())
- ->where("created_at", "<", Carbon::now()->startOfDay()),
- "this_week" => $this->where("created_at", ">=", Carbon::now()->startOfWeek()),
- "last_week" => $this->where("created_at", ">=", Carbon::now()->subWeek()->startOfWeek())
- ->where("created_at", "<", Carbon::now()->startOfWeek()),
- "this_month" => $this->where("created_at", ">=", Carbon::now()->startOfMonth()),
- "last_month" => $this->where("created_at", ">=", Carbon::now()->subMonth()->startOfMonth())
- ->where("created_at", "<", Carbon::now()->startOfMonth()),
- default => $this,
- };
- }
- }
|