Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jatanbhimani's avatar

Different form for create and edit in laravel filament

I am using laravel filament and i want to develop different forms in a resoruce for create and edit. I mean that i have 5 fields when i create and i want 3 fields only while editing it not other fields. how to do it?

0 likes
7 replies
tisuchi's avatar

@jatanbhimani You can use visible() method in your input.

Imagine that, you want to show the password field only during creating the user, but NOT during editing the user's data. In that case, you can simply use the visible in the form() method in your UserResource.

For example:

use Filament\Resources\Pages\CreateRecord;

public static function form(Form $form): Form
{
    return $form
        ->schema([
            TextInput::make('first_name')
                ->required(),

            TextInput::make('last_name')
                ->required(),

            TextInput::make('password')
                ->visible(fn ($livewire): bool => $livewire instanceof CreateRecord), // this will display in the create form only. 

        ]);
}
1 like
newbie360's avatar
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required()
                    ->maxLength(255),
                    // ...
                    
                    ->hiddenOn('edit')
                    
                    ->visibleOn('edit')
                    
                    ->disabledOn('edit')
                    
                    ->readOnlyOn('edit'),
            ]);
5 likes
delucaspinto's avatar

I like to do it this way:

public static function form(Form $form): Form
    {
        return $form
            ->schema(fn ($livewire)  => $livewire instanceof CreateRecord ? self::createSchema() : self::editSchema());
    }

    protected static function createSchema(): array
    {
        return [
            FileUpload::make('xml_file')
                ->directory('xmls')
                ->label('Selecione o arquivo xml')
                ->required()
                ->maxFiles(1),
        ];
    }

    protected static function editSchema(): array
    {
        return [
            TextInput::make('nome')
                ->label('Nome do Procedimento')
                ->required(),
            TextInput::make('descricao')
                ->label('Descrição do Procedimento')
                ->required(),
            // Outros campos para o modo Edit
        ];
    }
3 likes
svkhorolets's avatar

In case you are using version 3.x:

Inside Pages you have 3 files: CreateXXX.php EditXXX.php ListXXX.php

Inside any action you need add:

 public function form(Form $form): Form
    {
        return parent::form($form)->schema($this->getFormSchema());
    }

and put all fields inside:

protected function getFormSchema(): array
    {
        return [
            TextInput::make('email')
                ->required()
                ->email()
                ->unique('users', 'email'),
            ...
        ];
    }

I like this more, to keep logic, views inside related class.

amoktar's avatar

getFormSchema is deprecated

All you need is just overriding the form method in the CreateRecord/EditRecrd pages

Override the form() method to configure the default form.

app\Filament\Resources\PostResource\Pages\CreatePost.php

public function form(Form $form): Form
    {
		// return the form you want 
		return $form
            ->schema([ ]);
    }
2 likes

Please or to participate in this conversation.