F
Filament15mo 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
jop00OP15mo ago
Is duplicate all the table code from Resource.php to a livewire component the only way?
jop00
jop00OP15mo 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
awcodes15mo 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
jop00OP15mo ago
great, thanks!
Melody
Melody11mo ago
could you give me an example of this method?
awcodes
awcodes11mo 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
Melody11mo ago
cool, thank you
Want results from more Discord servers?
Add your server