diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index 9b33ea655..0722247aa 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -3,11 +3,12 @@ namespace Rappasoft\LaravelLivewireTables\Traits; use DateTime; +use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Relations\Relation; -use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities; use Rappasoft\LaravelLivewireTables\Views\Column; use Rappasoft\LaravelLivewireTables\Views\Filter; +use Illuminate\Database\Eloquent\Relations\Relation; +use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities; /** * Trait WithFilters. @@ -316,7 +317,8 @@ public function applySearchFilter($query) // TODO: Skip Aggregates if (! $hasRelation) { - $whereColumn = $query->getModel()->getTable() . '.' . $whereColumn; + $whereColumn = Schema::hasColumn($query->getModel()->getTable(), $whereColumn) ? $query->getModel()->getTable() . '.' . $whereColumn : $whereColumn; + } // We can use a simple where clause