Skip to content

Commit

Permalink
Merge pull request #1 from iYogesharma/v1.0
Browse files Browse the repository at this point in the history
added support for where in clause
  • Loading branch information
iYogesharma authored Sep 7, 2020
2 parents e3cc025 + f014779 commit 362ac5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "package to help in handling server side",
"version": "1.0",
"keywords": [
"iYogesharrma",
"iYogesharma",
"element-ui",
"vue-datatable",
"datatable",
Expand Down
29 changes: 28 additions & 1 deletion src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,34 @@ protected function setTotalData()
*/
protected function setFilters()
{
$this->query = $this->query->where($this->request->getFilters());
$filters = $this->request->getFilters();
$this->query = $this->query->where($filters['basic']);
if( count($filters['array']) > 0 )
{
$this->setArrayFilters( $filters['array']);
}

}

/**
* set array filter conditions on query
*
* @param array $filters
*/
protected function setArrayFilters( array $filters )
{
foreach($filters as $k => $v )
{
if( strpos($k,'_at') !== true || strpos($k,'date') !== true || strpos($k,'time') !== true)
{
$this->query = $this->query->whereBetween($k,$v);
}
else
{
$this->query = $this->query->whereIn($k,$v);
}

}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ public function hasFilters()
* @return array
*/
public function getFilters(){
return json_decode($this->request->input('filters'),true) ;
$filters = json_decode($this->request->input('filters'),true) ;
$arrayFilters = [];
foreach($filters as $k=>$v) {
if(gettype($v) === 'array') {
$arrayFilters[$k] = $v;
unset($filters[$k]);
}
}

return [ 'basic' => $filters, 'array' => $arrayFilters ];
}
}

0 comments on commit 362ac5f

Please sign in to comment.