Support virtual columns (only add table-prefix if column exists on table) #447
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey,
I was working on a project with a kind of complex query which powers the livewire-table. In the end, the values of three virtual columns are being displayed.
Since the package automatically adds the table prefix from the table of the query (
src/Traits/WithFilters.php
-320
), the search function does not work, because the virtual columns do only exist without the prefix.So I added checking if the column name exists on the given table via the
Schema
-Facade.The functionality should be the same + supporting virtual columns.
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.