Nested schema in filament v4

Good day everyone, I’m new to Filament and I’d like to ask if it’s possible (or allowed) to use a nested schema function inside another schema. Here’s my current setup. I created a tasks schema that returns a table:
public function tasks(Schema $schema): Schema
{
return $schema->components([
Table::make()
// table structure here
]);
}
public function tasks(Schema $schema): Schema
{
return $schema->components([
Table::make()
// table structure here
]);
}
And I also have a cardSchema:
public function cardSchema(Schema $schema): Schema
{
return $schema->components([
// schema here
]);
}
public function cardSchema(Schema $schema): Schema
{
return $schema->components([
// schema here
]);
}
What I’d like to do is reuse the tasks schema inside the cardSchema, something like this:
public function cardSchema(Schema $schema): Schema
{
return $schema->components([
$this->tasks
]);
}
public function cardSchema(Schema $schema): Schema
{
return $schema->components([
$this->tasks
]);
}
My question is: Is this the right way to include the tasks schema inside the cardSchema? If not, could you please suggest the correct approach or best practice for this kind of setup? I’m still learning Filament and trying to figure out the right patterns. Any advice would be appreciated.
2 Replies
Matthew
Matthew3d ago
I'm still on v3, so maybe wrong, but from glancing at your question, I would elevate the schema array into its own class and then call it from whereever I wanted.
ModestasV
ModestasV3d ago
Yes, it is allowed! But, you have to extract the schema itself (the array of schema) into a static method. Then call it anywhere else, like this TaskForm::getSchemaArray() and that should return you an array. Now, if you want to merge existing schema and the task schema, you need to do ...TaskForm::getSchemaArray() and it should work

Did you find this page helpful?