© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
39 replies
Abdur Razzaque

Conditional Form Input and Table Column

I want to create two types of data: 'image' or 'text.' That's why I've structured my code this way. Is there a more optimal approach? Additionally, I'd prefer to hide the 'Status' field on the Create form and reveal it in the Edit form. Please provide me with ideas on how to display input values in a table, where the value type can be either text or an image.

Section::make()->schema([
    TextInput::make('name'),
    Select::make('value_type')
        ->editOptionAction(null)
        ->options([
            'text' => 'Text',
            'image' => 'Image'
        ])->live(),

    TextInput::make('value')
        ->visible(fn (Get $get): string => $get('value_type') === 'text'),
    FileUpload::make('value')
        ->visible(fn (Get $get): string => $get('value_type') == 'image'),
    Select::make('Status')
])
Section::make()->schema([
    TextInput::make('name'),
    Select::make('value_type')
        ->editOptionAction(null)
        ->options([
            'text' => 'Text',
            'image' => 'Image'
        ])->live(),

    TextInput::make('value')
        ->visible(fn (Get $get): string => $get('value_type') === 'text'),
    FileUpload::make('value')
        ->visible(fn (Get $get): string => $get('value_type') == 'image'),
    Select::make('Status')
])
Solution
This code solved my problem.

<div>
    @if ($getRecord()->value_type === 'text')
        {{ $getState() }}
    @else
        <img class='h-6' src='{{ Storage::url($getState()) }}' />
    @endif
</div>
<div>
    @if ($getRecord()->value_type === 'text')
        {{ $getState() }}
    @else
        <img class='h-6' src='{{ Storage::url($getState()) }}' />
    @endif
</div>
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

conditional table column
FilamentFFilament / ❓┊help
3y ago
Conditional rendering a table column
FilamentFFilament / ❓┊help
3y ago
Search input per table column
FilamentFFilament / ❓┊help
3y ago
Conditional actions on table columns
FilamentFFilament / ❓┊help
11mo ago