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

Need Help Customizing Relationship Field Labels in Filament AutoResource #4

Open
SouhailBouaouiss opened this issue Feb 20, 2024 · 3 comments

Comments

@SouhailBouaouiss
Copy link

I'm encountering a problem with customizing column labels for relationship fields in a Filament resource. Specifically, I'm using the getColumnsOverwrite method to modify the columns displayed in tables, forms, and infolists. However, when attempting to modify the labels for relationship fields such as users.name and category.name, the changes don't seem to take effect as expected.
Sure, here's a description of your issue that you can use to ask the community:

Expected Behavior:

I expect that by specifying custom labels using the label method for relationship fields in the getColumnsOverwrite method, the column labels in the generated views (tables, forms, etc.) should be updated accordingly.

Actual Behavior:

Despite specifying custom labels for relationship fields, such as users.name and category.name, using the label method in the getColumnsOverwrite method, the column labels remain unchanged in the generated views. The labels continue to display the default relationship field names (users.name and category.name) instead of the specified custom labels.

@miguilimzero
Copy link
Owner

@SouhailBouaouiss, I could not understand what you are trying to do. I think it's not possible to set custom labels with filament auto panel without some kind of trick.

Can you share a code example of what you are trying to do?

@SouhailBouaouiss
Copy link
Author

SouhailBouaouiss commented Feb 22, 2024

@miguilimzero In my database schema, I have a column named category_id, which serves as a foreign key referencing the id column in the categories table. To display the corresponding category name instead of the category ID in my application, I have established a relationship between the category_id column and the categories table But I can not get the category name instead of the category id in the table.

@miguilimzero
Copy link
Owner

I think you cannot do that. You are trying to overwrite the column category.id with category.name, and this does not work. You can only overwrite columns with the same name. Or you can add new columns with the trick described at #1.

The auto panel tries to guess the relationship column here in case you want to customize: https://github.com/miguilimzero/filament-auto-panel/blob/main/src/Generators/AbstractGenerator.php#L105-L123

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