Filament: How to Structure Longer Resource Files?

preview_player
Показать описание
What if your Filament Resource Class is 1000 lines of code? Is thad bad? And how could we shorten it?
Рекомендации по теме
Комментарии
Автор

One common pattern I've seen is people moving methods like `form()` and `table()` to single-use traits to make the files shorter and more easily digestible - or something.

Personally, I think I agree with Povilas that `getFormSchema()` could be 2 methods instead of using the parameter.

danharrin
Автор

Wow! Thank you very much Povilas for taking the question. Tried traits but honestly I was unable to get running in a simple way. All was a mess when applied to modal forms triggered from action buttons conditioned by state machine classes.

This is a very rude approach, but finally I rely on the foldable paragraphs of the editor (VSC in my case), putting a section comment line then over tabbed the code of the action button + modal form. At least when all sections are folded it is much clear and reachable than before.

Thankfully the form is running fine now with 6 sections, 54 fields (conditional some of them), 8 state action buttons and a relation manager. All as customer asked (Financial CP). Filament is a great tool!

Buscalia
Автор

I create “Schema” classes under the resource folder and name them accordingly. I then have a simple get method in the class that returns an array of fields. Works very well for one of the big e-commerce projects I work on

alexbirtwell
Автор

To avoid duplication I prefer schema even the form in separate files

SuvroImran
Автор

hello, sir please make your next topic about this problem please you already replied to me about the topic of adding this for future videos but can you make your next video about this functionality, How can we make is_admin Currently we can get (403 error forbidden) but I want validation in only admin login page if user is_admin = 0 this will show "you are not an admin" in login page and if user is_admin = 1 we can go into dashboard how can we archive this functionality? Please let me know.

devkumarverma