Skip to content

Commit

Permalink
unique key
Browse files Browse the repository at this point in the history
  • Loading branch information
KasparRosin committed Jan 19, 2021
1 parent 8a82b19 commit 7034035
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class InputFilter extends Filter
{
public $component = 'nova-input-filter';
public array $options = [];
public $options = [];

public function __construct($options = null, $name = null)
{
Expand All @@ -21,13 +21,6 @@ public function apply(Request $request, $query, $search)
return $query->where(function ($query) use ($search) {
$model = $query->getModel();
$connectionType = $query->getModel()->getConnection()->getDriverName();
$canSearchPrimaryKey = is_numeric($search) &&
in_array($query->getModel()->getKeyType(), ['int', 'integer']) && ($connectionType != 'pgsql' || $search <= PHP_INT_MAX) &&
in_array($query->getModel()->getKeyName(), static::$search);

if ($canSearchPrimaryKey) {
$query->orWhere($query->getModel()->getQualifiedKeyName(), $search);
}

$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';

Expand All @@ -45,4 +38,14 @@ public function options(Request $request)
{
return $this->options;
}

public function key()
{
$isUniqueClass = get_class($this) !== InputFilter::class;

if (!empty($this->name) && !$isUniqueClass)
return get_class($this) . str_replace(' ', '', $this->name);

return parent::key();
}
}

0 comments on commit 7034035

Please sign in to comment.