Skip to content

Commit

Permalink
Merge pull request #20 from bluefyn-international/chore/null-contains
Browse files Browse the repository at this point in the history
Updating contains and does not cotains to handle null
  • Loading branch information
Quentin Schmick authored Jul 20, 2022
2 parents 883e67a + 68d4bd7 commit 2cb3717
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/BaseFeatures/Filters/ContainsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BluefynInternational\ReportEngine\BaseFeatures\Filters;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;

class ContainsFilter extends BaseFilter
{
Expand All @@ -25,9 +26,9 @@ public function apply(Builder $builder, array $options = []) : Builder
*
* @return Builder
*/
public static function build(Builder $builder, $field, $value, string $action = 'where') : Builder
public static function build(Builder $builder, mixed $field, mixed $value, string $action = 'where') : Builder
{
return $builder->$action($field, 'like', '%' . $value . '%');
return $builder->$action(DB::raw('COALESCE(' . $field . ", '')"), 'like', '%' . $value . '%');
}

/**
Expand Down
16 changes: 14 additions & 2 deletions src/BaseFeatures/Filters/DoesNotContainFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BluefynInternational\ReportEngine\BaseFeatures\Filters;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;

class DoesNotContainFilter extends BaseFilter
{
Expand All @@ -14,9 +15,20 @@ class DoesNotContainFilter extends BaseFilter
*/
public function apply(Builder $builder, array $options = []) : Builder
{
$action = $this->getAction();
return self::build($builder, $this->getField(), $this->getValue(), $this->getAction());
}

return $builder->$action($this->getField(), 'not like', '%' . $this->getValue() . '%');
/**
* @param Builder $builder
* @param mixed $field
* @param mixed $value
* @param string $action
*
* @return Builder
*/
public static function build(Builder $builder, mixed $field, mixed $value, string $action = 'where') : Builder
{
return $builder->$action(DB::raw('COALESCE(' . $field . ", '')"), 'not like', '%' . $value . '%');
}

/**
Expand Down

0 comments on commit 2cb3717

Please sign in to comment.