Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by relation column #11

Closed
michalkozikcombc opened this issue May 30, 2016 · 2 comments
Closed

Filter by relation column #11

michalkozikcombc opened this issue May 30, 2016 · 2 comments

Comments

@michalkozikcombc
Copy link

How can I use FilterControl in Grid by relation of Eloquent model? For example:
I have DocumentActivity model assigned to User model. I can set
$provider = new EloquentDataProvider(DocumentActivity::class);
new FilterControl('user_id', FilterOperation::OPERATOR_LIKE, $input->option('user_id'))
but in this filter i can type only user_id, i want to filter by e.g user name.
How can i do that?

@Nayjest
Copy link
Member

Nayjest commented May 30, 2016

Hi!
It's not possible becouse of Laravel architecture: relations are loaded in separate queries to DB.
So,
a) You can write a query with sql joins instead of using Laravel relations if you want to filter by related table fields (recommended solution)

b) You can preload all data and use it with ArrayDataProvider to filter by specific fileds, (it's not recommended solution due to potential performance issues) + looks like you will need to override filtering method inside FilterControl

@michalkozikcombc
Copy link
Author

Roger that. I thought the grid has some function like that. I will use first solution. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants