Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1639 from guanguans/2.0
添加 `FIND_IN_SET` 类型查询过滤
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |