F
Filamentβ€’11mo ago
Treebeard

Clean up verbosity of Filament form

Hello everyone, I have a fairly complex form with many layouts and repeaters. The "form" method of my resource is very verbose and indented. I find it challenging sometimes to read. Therein lies my question, are there any standard practices around cleaning up the "form()"? For instance, moving a section to a separate method. Thanks in advance
Solution:
here is one way to do it, this is a very stripped down example, but should get the point across 😊 that way you can split it how ever you like, bonus that you can just ctrl + click in your IDE to get to that code easily ```php...
Jump to solution
2 Replies
Solution
dissto
disstoβ€’11mo ago
here is one way to do it, this is a very stripped down example, but should get the point across 😊 that way you can split it how ever you like, bonus that you can just ctrl + click in your IDE to get to that code easily
public static function form(Form $form): Form
{
return $form
->schema([
static::myRepeaterThatDoesA(),
static::myRepeaterThatDoesB(),
// whatever
]);
}

// in the same resource
public static function myRepeaterThatDoesA()
{
return
Forms\Components\Repeater::make('xxx');
}

public static function myRepeaterThatDoesB()
{
return
Forms\Components\Repeater::make('yyy');
}
public static function form(Form $form): Form
{
return $form
->schema([
static::myRepeaterThatDoesA(),
static::myRepeaterThatDoesB(),
// whatever
]);
}

// in the same resource
public static function myRepeaterThatDoesA()
{
return
Forms\Components\Repeater::make('xxx');
}

public static function myRepeaterThatDoesB()
{
return
Forms\Components\Repeater::make('yyy');
}
Treebeard
TreebeardOPβ€’11mo ago
That's exactly what I was looking for! Thank you, MUCH cleaner
Want results from more Discord servers?
Add your server