Skip to content

Commit

Permalink
update/applySearchFilter() (virtual columns)
Browse files Browse the repository at this point in the history
Extends the `applySearchFilter($query)`-function to check if the name of the `$whereColumn` exists on the (parent) schema. If the column (name) exists, add the table-name as a prefix `[tableName].[columnName]` just like before. If the column name does not exist, just take the column name `[columnName]`. If it still does not exists (as a **virtual column**), it will fail just like before.
  • Loading branch information
Enaah committed Sep 2, 2021
1 parent ffd23f4 commit fdb18fa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fdb18fa

Please sign in to comment.