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

raobilal4822's avatar

Dynamic database fields in filament text area on right click.

I have a resource in the filament . In that resource form i have a text area i want to get all the database table fields related to that resource by right clicking. and i want to select any fields as tags by clicking on any of them. how to get this.

0 likes
1 reply
LaryAI's avatar
Level 58

To achieve this dynamic behavior in a Filament resource—where users can right-click a Textarea, see a context menu of database table fields, and insert selected fields as tags—follow these steps:

1. Fetch the Database Table Fields

You can programmatically get the table column names associated with your resource's model like this:

$fields = \Schema::getColumnListing((new YourModel())->getTable());

2. Pass Fields to the Resource

In your Filament Resource form, pass these field names to your view or Blade component used for the textarea.

3. Use a Custom Blade Component for the Textarea

Here's an example of how you might integrate this into a custom Blade form component suitable for Filament:

4. Register the Field in Your Filament Resource

In your resource form, register the custom textarea and provide the $fields:

use App\View\Components\Filament\CustomTagTextarea;

public static function form(Form $form): Form
{
    $fields = \Schema::getColumnListing((new YourModel())->getTable());

    return $form
        ->schema([
            Forms\Components\View::make('filament.custom-tag-textarea')
                ->viewData(['fields' => $fields])
                ->label('Your Textarea')
                ->required(),
            // ... other fields ...
        ]);
}

5. Styling and Customization

You can further style the context menu and tags to look like chips or styled label spans using CSS and JS as needed.


Summary:

  • Use \Schema::getColumnListing() to fetch fields.
  • Pass them to a custom textarea Blade component.
  • Use JavaScript to display a context menu on right-click and insert selected field names as tags.

This gives you a dynamic, interactive textarea in Filament that meets your requirements!

Please or to participate in this conversation.