nova-json-schema-field
nova-json-schema-field copied to clipboard
Set schema dinamically
Hi there. Loving this package. Any ideas how can I implement this in a way that I can solve the schema
on runtime?
Let's say you have User
that belongs to Organization
. The Organization
has their required fields stored in them. So when editing a User
you can say: the fields for this User
belonging to some Organization
are given by $this->schema($resource)
or something like that.
Hello. If i got it right:
- In user fields you just NovaJsonSchemaField::make('Settings', $this->schema())
- $this->schema() returns your user->organization->schema or empty array (in case of creation of a new User)
Hey @NikolaySav! Thanks for replying.
This works only when showing the edit form. But when saving (POST), $this
is not filled yet, so I can't have required fields.
Can you share your code?
When displaying the edit form, onfields(Request $request)
method you can do if ($this->organization)
.
When submitting form, onfields(Request $request)
method you can't do if ($this->organization)
becase the resource is not filled with the model attributes.
This would be really nice. I think it could be achieved by using merge on a belongsto field and this one - similar to the way the Place field interacts with other address fields.
Also it seems like the type inside schema is not used atm. Support for select would be nice too.