What is the best way to re-use schemas when just using tables/forms packages?

I am just starting to build an app that will just use the tables/forms package. I've started with a simple model and a "create model" component. It's a bit complex, so it's still a work in progress. In any case, I'm far enough along where I can see that I will have to basically recreate the same form definition for an "edit model" component. I'm wondering what the best/recommended way might be to keep the definition in one place...? When using the admin package, the schema is defined once and you can show/hide/whatever based on whether you're creating/editing. I can't seem to find how one might be able to do this when just using tables/forms. I hope this makes sense. Thx in advance for any help. 🤓
9 Replies
Dan Harrin
Dan Harrin2y ago
question makes sense but i think you're overcomplicating its just PHP you can return a form schema or table columns array from anywhere Invokable class, any method, static method and just pass it in
Travis
TravisOP2y ago
OK. That makes sense, of course, but that suggests that there's nothing "built-in"....like we have in the admin package, right...?
Dan Harrin
Dan Harrin2y ago
i dont see the need for anything to be built in?
Travis
TravisOP2y ago
So...just have the schema any ol' place and (re)use for both create/edit....sounds simple enough. Thx.
Dan Harrin
Dan Harrin2y ago
define a getFormSchema() static method on your model and return from there or on a wrapper around your model
Travis
TravisOP2y ago
Well, in the admin package, there is the WidgetResource, which has the form/table definitions...and the form definitions are used for the CreateWidget and EditWidget classes. That's what I was talking about. 🤓
Dan Harrin
Dan Harrin2y ago
a resource is just a model wrapper so you can write your own any old PHP class will work you could even put getFormSchema() in a trait and reuse it between components that would also work
wyChoong
wyChoong2y ago
Well you can have App\Resources if that makes you feel more like home 😂
Travis
TravisOP2y ago
@Dan Harrin Thx...! 👍
Want results from more Discord servers?
Add your server