F
Filament7mo ago
Zod

How can I add fields to / extend a resource from a plugin

I want to add a form field to an existing module/plugin we are using. I already tried extending the class and overwriting the form method but thats not working. Any idea how this could be done?
Solution:
I made them, now it works!
Jump to solution
12 Replies
Dennis Koch
Dennis Koch7mo ago
The plugins needs to provide the option. Otherwise you need to extend the resouce and add your classes, but I guess it's easier to just copy over stuff.
Zod
ZodOP7mo ago
Thanks! How do I provide this option? I am not sure what you mean by providing the option by the plugin, is there an option which alows extending? It's a module/plugin (the resource) we are using in multiple projects. But in one project we need 1 extra field for that resource. So I need to add it in the project but not in the module. So I extended the moduled resource and made the project use the custom one that extended the module. Here I would like to overwrite the form function or add the field.
Dennis Koch
Dennis Koch7mo ago
You could define a method like getFormSchema that returns the schema as an array which is used in form() then. That one could be extended and you could add fields before or after.
Zod
ZodOP7mo ago
Do you have an example? I am having trouble firing a non static getFormSchema in the static form function.
Dennis Koch
Dennis Koch7mo ago
Well it should be static then?!
Zod
ZodOP7mo ago
I thought static functions could not be extended? Trying it with static:: but no luck unfortunally class ResourceCompanyResource extends Resource { public static function form(Form $form): Form { return $form ->schema(static::getFormSchema())->columns(1); } public static function getFormSchema(): array { return [ Tabs::make() ->tabs([ Tab::make('Information') ->schema(static::getInformationTabSchema()), Tab::make('Invoice') ->schema(static::getInvoiceTabSchema()), Tab::make('Financial') ->schema(static::getFinancialTabSchema()) ]) ]; } } class CompanyResource extends ResourcesCompanyResource { public static function getFormSchema(): array { return [ Tabs::make() ->tabs([ Tab::make('Information2') ->schema(static::getInformationTabSchema()), Tab::make('Invoice') ->schema(static::getInvoiceTabSchema()), Tab::make('Financial') ->schema(static::getFinancialTabSchema()) ]) ]; } }
Dennis Koch
Dennis Koch7mo ago
What’s the issue? Are the resource pages actually using the extended resource?
Zod
ZodOP7mo ago
Im trying to make Information2 overwrite Information but its still showing Information The CompanyResource is actually extending ResourcesCompanyResource Should it work like this you think?
Dennis Koch
Dennis Koch7mo ago
But the Create and EditPage? Do you have separate ones for the second resource?
Zod
ZodOP7mo ago
No, I don't. Only for the one that is getting extended
Solution
Zod
Zod7mo ago
I made them, now it works!
Zod
ZodOP7mo ago
Thanks mate
Want results from more Discord servers?
Add your server