Skip to content

Commit

Permalink
Merge pull request #1639 from guanguans/2.0
Browse files Browse the repository at this point in the history
添加 `FIND_IN_SET` 类型查询过滤
  • Loading branch information
jqhph committed Jan 18, 2022
2 parents 16d8239 + c4a91b1 commit ce145f5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Grid/Filter.php
Expand Up @@ -13,6 +13,7 @@
use Dcat\Admin\Grid\Filter\Day;
use Dcat\Admin\Grid\Filter\EndWith;
use Dcat\Admin\Grid\Filter\Equal;
use Dcat\Admin\Grid\Filter\FindInSet;
use Dcat\Admin\Grid\Filter\Group;
use Dcat\Admin\Grid\Filter\Gt;
use Dcat\Admin\Grid\Filter\Hidden;
Expand Down Expand Up @@ -66,6 +67,7 @@
* @method Hidden hidden($name, $value)
* @method Group group($column, $builder = null, $label = '')
* @method Newline newline()
* @method FindInSet findInSet($column, $label = '')
*/
class Filter implements Renderable
{
Expand Down Expand Up @@ -107,6 +109,7 @@ class Filter implements Renderable
'year' => Year::class,
'hidden' => Hidden::class,
'newline' => Newline::class,
'findInSet' => FindInSet::class,
];

/**
Expand Down
38 changes: 38 additions & 0 deletions src/Grid/Filter/FindInSet.php
@@ -0,0 +1,38 @@
<?php

namespace Dcat\Admin\Grid\Filter;

use Illuminate\Support\Arr;

class FindInSet extends AbstractFilter
{
/**
* Input value from presenter.
*
* @var mixed
*/
public $input;

/**
* Get condition of this filter.
*
* @param array $inputs
* @return array|mixed|void
*/
public function condition($inputs)
{
$value = Arr::get($inputs, $this->column);

if ($value === null) {
return;
}

$this->input = $this->value = $value;

$query = function ($query) {
$query->whereRaw("FIND_IN_SET(?, $this->column)", $this->value);
};

return $this->buildCondition($query->bindTo($this));
}
}

0 comments on commit ce145f5

Please sign in to comment.