Share the same $form and $table between Resource, RelationshipManager, createOptionForm

Hi, I'm new to filamentphp, and mostly a Front-end developer. I've had to add some things in an existing project, and haven't had too much problems, but I feel like I keep repeating the same forms and fields over and over... Is there a way to define the fields once, and reuse them between the Resource, RelationshipManager and createOptionForm ? And what is the best practices around that ?
8 Replies
mrleblanc101
mrleblanc101OP4mo ago
Exemple:
No description
No description
mrleblanc101
mrleblanc101OP4mo ago
The problem is that if I add a field, I need to remember to add it to all 3 places !
mrleblanc101
mrleblanc101OP4mo ago
@Exi Thank you, since this is the v4 docs, was this not documented at all in v3, or is it somewhere else in the doc ? @Exi How would that with createOptionForm since I can't pass $schema to configure ? Nvm I found out how: ->createOptionForm(fn(Form $form) => AuthorResource::form($form))
mrleblanc101
mrleblanc101OP4mo ago
@Exi So I would create a Schemas folder inside my Resources like so ? Is there a reason why my resource is not inside that same folder ? I'm on v3, and use the CLI like so the create the model and resources:
php artisan make:filament-resource AiProvider
php artisan make:model AiProvider
php artisan make:filament-resource AiProvider
php artisan make:model AiProvider
No description
Exi
Exi4mo ago
Neither v3 nor v4 enforces a folder structure. The v4 docs just give an example. Use any layout you like; putting the resource in Schemas is okay, I think.
mrleblanc101
mrleblanc101OP4mo ago
The CLI generated drastically different output
Exi
Exi4mo ago
You can stick to that layout if you prefer

Did you find this page helpful?