Multi-use form section??
Sir i have a question, i have common segments of form in my 3 or 4 resources. Now what I want is to create these segments once and use them in different resource pages.. is that possible to do.??
1 Reply
Yes it's possible to do.
Create the Form Component:
Open your terminal or command prompt.
Navigate to your Laravel project directory.
Run the following command to generate a new Filament component:
php artisan make:filament-component CommonFormComponent
Then edit the component created
// app/Filament/Components/CommonFormComponent.php
namespace App\Filament\Components;
use Filament\Forms\Component;
use Filament\Forms\Components\TextInput;
class CommonFormComponent extends Component
{
public function fields()
{
return [
TextInput::make('name')
->label('Name'),
TextInput::make('email')
->label('Email'),
TextInput::make('phone')
->label('Phone Number'),
];
}
}
Then, use it in your resource page
// app/Filament/Pages/UserPage.php
namespace App\Filament\Pages;
use App\Filament\Components\CommonFormComponent;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Tab;
class UserPage extends Page
{
public function form()
{
return Grid::make()
->columns(
Tab::make('Details', [
CommonFormComponent::make(),
// Other form components specific to this page
]),
);
}
}
Then, register inside the filament service provider
// app/Providers/FilamentServiceProvider.php
use App\Filament\Components\CommonFormComponent;
protected $components = [
CommonFormComponent::class,
// Other custom components
];