FindInSet.php 731 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Dcat\Admin\Grid\Filter;
  3. use Illuminate\Support\Arr;
  4. class FindInSet extends AbstractFilter
  5. {
  6. /**
  7. * Input value from presenter.
  8. *
  9. * @var mixed
  10. */
  11. public $input;
  12. /**
  13. * Get condition of this filter.
  14. *
  15. * @param array $inputs
  16. * @return array|mixed|void
  17. */
  18. public function condition($inputs)
  19. {
  20. $value = Arr::get($inputs, $this->column);
  21. if ($value === null) {
  22. return;
  23. }
  24. $this->input = $this->value = $value;
  25. $query = function ($query) {
  26. $query->whereRaw("FIND_IN_SET(?, $this->column)", $this->value);
  27. };
  28. return $this->buildCondition($query->bindTo($this));
  29. }
  30. }