abdullah_arrusi
abdullah_arrusi
FFilament
Created by abdullah_arrusi on 9/14/2023 in #❓┊help
Pass non-related for <model> data in form builder <select> from <another model> with custom query
I have a model with 4 relationships. But on create page I need to render additional select field that are not related with my model attributes and relationships. When saving, this data from select fields must be converted into JSON contents to save select fields (initially not-related with my model) into JSONB. Some select fields need to provide data from a large tables. This could be several million entries, for example, searching for a user by full name. If I understand the documentation correctly, I cannot use the ->relationship(name: ..., titleAttribute: ...) method in this case - because it only works with related models. Or can it still be used for unrelated models? How to provide data from unrelated table to my select? I have 2 cases of using such selects: - unrelated tables are highloaded - unrelated tables are a small directory (less than 100 records in the table - for example, a list of regions). 1) In the first case, I use the ->searchable() method. How can I properly set up a search in unrelated tables so that the select searches for data only on certain columns? In this case, I see it advisable to immediately transfer, for example, users with the highest ratings to the select when loading the page for the first time. But if you enter a first name and last name, then the select should search strictly by first and last name. I also need to limit the number of options displayed in the selector. 2) In the second case, I want the page to be loaded with data from a small table when it is first loaded, so as not to wait for the search field in the select to send a request to the backend and return the data back. How to do it? Please show me a usage example for all my questions.
2 replies