Skip to content

Commit ba141e1

Browse files
committed
Merge branch 'feature-searchable' of https://github.com/DeltaSystems/laravel-livewire-tables into feature-searchable
2 parents e82678a + c02773f commit ba141e1

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/Utilities/ColumnUtilities.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Rappasoft\LaravelLivewireTables\Utilities;
44

55
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6-
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Database\Query\Builder as Builder;
87
use Illuminate\Support\Str;
98

@@ -66,23 +65,22 @@ public static function hasWildcardMatch($column, $searchColumns)
6665
return count(array_filter($searchColumns ?? [], function ($searchColumn) use ($column) {
6766

6867
// match wildcards such as * or table.*
69-
$hasWildcard = Str::endsWith($searchColumn, '*');
68+
$hasWildcard = Str::endsWith($searchColumn, '*');
7069

71-
// if no wildcard, skip
72-
if (! $hasWildcard) {
73-
return false;
74-
}
75-
76-
if (! self::hasRelation($column)) {
77-
return true;
78-
} else {
79-
$selectColumnPrefix = self::parseRelation($searchColumn);
80-
$columnPrefix = self::parseRelation($column);
70+
// if no wildcard, skip
71+
if (! $hasWildcard) {
72+
return false;
73+
}
8174

82-
return $selectColumnPrefix === $columnPrefix;
83-
}
75+
if (! self::hasRelation($column)) {
76+
return true;
77+
} else {
78+
$selectColumnPrefix = self::parseRelation($searchColumn);
79+
$columnPrefix = self::parseRelation($column);
8480

85-
})) > 0;
81+
return $selectColumnPrefix === $columnPrefix;
82+
}
83+
})) > 0;
8684
}
8785

8886
/**
@@ -165,20 +163,16 @@ public static function mapToSelected($column, $queryBuilder)
165163

166164
// this is easiest when using the eloquent query builder
167165
} elseif ($queryBuilder instanceof EloquentBuilder) {
168-
169166
$relation = $queryBuilder->getRelation($relationName);
170167
$possibleTable = $relation->getModel()->getTable();
171-
172168
} elseif ($queryBuilder instanceof Builder) {
173169

174170
// @todo: possible ways to do this?
175171
$possibleTable = null;
176-
177172
} else {
178173

179174
// we would have already returned before this is possible
180175
$possibleTable = null;
181-
182176
}
183177

184178
// if we found a possible table

tests/ColumnUtilitiesTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests;
44

5-
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
6-
use Illuminate\Support\Collection;
7-
use Rappasoft\LaravelLivewireTables\DataTableComponent;
8-
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
95
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
106
use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities;
117

0 commit comments

Comments
 (0)