Skip to content

Filament – Using existing database entries to create TextInput field hints

Whilst working in Laravel and coding up a not-so-simple CRUD page in Filament, I searched high and dry to find out how to create a hint for a TextInput. The official documentation for Filament is brilliant but sometimes limited in their usage examples.

Apologies for the long winded title.

This article is short and sweet.

Whilst working in Laravel and coding up a not-so-simple CRUD page in Filament, I searched high and dry to find out how to create a hint for a TextInput.

The official documentation for Filament is brilliant but sometimes limited in their usage examples.

Here’s their guide to TextInputs – https://filamentphp.com/docs/3.x/forms/fields/text-input

But here is the magic, not shown in their documentation:

This magic goes in app/Filament/{PANELNAME}/Resources/{RESOURCENAME}Resource.php

Use the below TextInput in your schema and replace the {VALUES} with the correct references in your models/resources.

                        Forms\Components\TextInput::make('{FIELDNAME}')
                            ->required()
                            ->reactive()
                            ->datalist({MODELNAME}::all()->pluck('{FIELDTOUSEASVALUE}', '{FIELDTOSHOW}')),

And it’s as simple as that.

Happy coding

Share the Post:

Related Posts