PlanFilter.php 794 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\ModelFilters;
  3. use Carbon\Carbon;
  4. use EloquentFilter\ModelFilter;
  5. class PlanFilter extends ModelFilter
  6. {
  7. /**
  8. * Related Models that have ModelFilters as well as the method on the ModelFilter
  9. * As [relationMethod => [input_key1, input_key2]].
  10. *
  11. * @var array
  12. */
  13. public $relations = [];
  14. public function expired($expired): PlanFilter
  15. {
  16. if (! in_array($expired, ['yes', 'no'])) {
  17. return $this;
  18. }
  19. return $this->when($expired == "yes", function ($query) {
  20. return $query->where('end', "<=", Carbon::now()->toDateString());
  21. })->when($expired == "no", function ($query) {
  22. return $query->where('end', ">", Carbon::now()->toDateString())->orWhereNull('end');
  23. });
  24. }
  25. }