miguilimzero / filament-auto-panel

Construct your Filament panel Resources and Relation Managers at execution time like magic.
MIT License
25 stars 3 forks source link

Need Help Customizing Relationship Field Labels in Filament AutoResource #4

Open SouhailBouaouiss opened 4 months ago

SouhailBouaouiss commented 4 months ago

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 commented 4 months ago

@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 commented 4 months ago

@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 commented 4 months ago

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 https://github.com/miguilimzero/filament-auto-panel/issues/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