CustomFieldFilter.php 671 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\ModelFilters;
  3. use EloquentFilter\ModelFilter;
  4. class CustomFieldFilter extends ModelFilter
  5. {
  6. /**
  7. * Related Models that have ModelFilters as well as the method on the ModelFilter
  8. * As [relationMethod => [input_key1, input_key2]].
  9. *
  10. * @var array
  11. */
  12. public $relations = [];
  13. public function group($group)
  14. {
  15. return $this->where("group", $group);
  16. }
  17. public function batch($batch)
  18. {
  19. $in = [];
  20. foreach ($batch as $item) {
  21. $in[] = sprintf("'%s'", $item);
  22. }
  23. return $this->whereRaw(sprintf("concat(`group`, '.', `key`) in (%s)", implode(',', $in)));
  24. }
  25. }