My Resorce has Form I want to call it or inheritance this form in another palce
My Resorce has Form I want to call it or inheritance this form in another palce How do it
$formSchema = TaskResource::form();
> dd( $formSchema);
5 Replies
I want to call form in another Resorsce
Thanks ,but alsoe I want use it in Widgets like getFormSchema
you can define a getForm static method in the corresponding model then call the form in any resource you want
Eg if you have a tag model and the resources, in the Tag model define a new methid like so
public static function getForm(): array
{
return [
TextInput::make('name')
->required()
->maxLength(255),
ColorPicker::make('color')
->required(),
];
}
Then in the tagresource form method do this
public static function form(Form $form): Form
{
return $form
->schema(Task::getForm());
}
I suppose you have a userresource and you might want to create a new tag without necessarily goung back to the tag resource, so in the tag form component of the userresource form method you can chain the method createOptionForm(App\Models\Tag::getForm()) and have it complete as so
Select::make('tags')
->relationship('tags', 'name',)
->multiple()
->searchable()
->preload()
->createOptionForm(Tag::getForm())
Hope this is what youre looking for