F
Filamentβ€’17mo ago
Abel Cobreros

Is it possible to get form from resource and add it to createOptionForm?

As the title says, I don't like having to repeat the content of the form in a section and in any other select field that has a createOptionForm method on it. I guess I can just put it on a helper function in a service class or something but I was wondering if it would be possible to do it in a nicer way.
Solution:
So we do it like this within the activity plugin: $form = static::getResource()::form(new Form($this)); You could also put a static array return function within the resource file and call that single function each time πŸ™‚...
Jump to solution
5 Replies
toeknee
toekneeβ€’17mo ago
Sure, get the Resource and then the form as a method call?
Solution
toeknee
toekneeβ€’17mo ago
So we do it like this within the activity plugin: $form = static::getResource()::form(new Form($this)); You could also put a static array return function within the resource file and call that single function each time πŸ™‚
Abel Cobreros
Abel CobrerosOPβ€’17mo ago
Thanks! I actually went for the second option, nice and clean.
toeknee
toekneeβ€’17mo ago
Welcomes, it’s what I do. You could also look at building a schema folder and containing all your forms for each model type in here and structure it that way πŸ™
Tieme
Tiemeβ€’15mo ago
For a nice online solution, this is what i am using now. ''' ->createOptionForm(fn(Form $form) => OrderVatResource::form($form)) '''
Want results from more Discord servers?
Add your server