123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\ModelFilters;
- use Carbon\Carbon;
- use EloquentFilter\ModelFilter;
- class PlanFilter 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 expired($expired): PlanFilter
- {
- if (! in_array($expired, ['yes', 'no'])) {
- return $this;
- }
- return $this->when($expired == "yes", function ($query) {
- return $query->where('end', "<=", Carbon::now()->toDateString());
- })->when($expired == "no", function ($query) {
- return $query->where('end', ">", Carbon::now()->toDateString())->orWhereNull('end');
- });
- }
- }
|