CustomFieldFilter.php 763 B

1234567891011121314151617181920212223242526272829303132333435
  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 key($key){
  18. return $this->where("key", "like", "%$key%");
  19. }
  20. public function batch($batch)
  21. {
  22. $in = [];
  23. foreach ($batch as $item) {
  24. $in[] = sprintf("'%s'", $item);
  25. }
  26. return $this->whereRaw(sprintf("concat(`group`, '.', `key`) in (%s)", implode(',', $in)));
  27. }
  28. }