F
Filament16mo ago
jop00

Reusing tables and forms from Resources

Is it possible to reuse a table/form from Resources on the public side of the web?
9 Replies
jop00
jop00OP16mo ago
Is duplicate all the table code from Resource.php to a livewire component the only way?
jop00
jop00OP16mo ago
I mean using the same form code used in the panel resources as an independent component to anywhere of the non admin panel part without duplicate all the form schema and everything.
awcodes
awcodes16mo ago
yes, create a method on the resource that return the array of form fields. then you can get that array anywhere in your app by calling it from the resource. meaning you can load it into the schema of any form
jop00
jop00OP16mo ago
great, thanks!
Melody
Melody12mo ago
could you give me an example of this method?
awcodes
awcodes12mo ago
It’s a standard php OOP thing. On the resource, some people do it on the model, but basically:
public function myFormSchema(): array
{
return [
TextInput::make(),
Select::make(),
];
}
public function myFormSchema(): array
{
return [
TextInput::make(),
Select::make(),
];
}
The you can call that method in the form schema:
$form->schema($this->myFormSchema())
$form->schema($this->myFormSchema())
If you intend to use the form in other places though you’ll probably want to make it static though.
Melody
Melody12mo ago
cool, thank you

Did you find this page helpful?