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

kikloo's avatar

Getting error while defining enum options in Filament Select

Hi,

I'm following the Laracast Rapid Dev. with Filament and I'm not able to specify options for the filament select component. I get the following error:

Filament\Forms\Components\Select::getOptions(): Return value must be of type array, string returned

My enum file is following:

<?php

namespace App\Enums;

enum Status: string
{
    case Active = 'Active';
    case Inactive = 'Inactive';
}

And my filament code is:

                Forms\Components\Select::make('status')
                    ->enum(Status::class)
                    ->options(Status::class),

As soon as I remove the options the page works just that options are not coming. What am I doing wrong ? I have done everything I can think of and even deleted the whole project and start again but same error.

Thanks in advance.

0 likes
3 replies
LaryAI's avatar
Level 58

It looks like you're trying to use the enum method on the Select component, but you're also calling options with the enum class as an argument, which is not necessary. The enum method is used to automatically generate options from an enum class, so you don't need to call options separately.

Here's how you can define the select component with enum options correctly:

Forms\Components\Select::make('status')
    ->enum(Status::class)

This will automatically use the enum values as options for the select component. The enum method will take care of converting the enum cases to the appropriate key-value pairs for the select options.

If you want to manually specify the options for some reason, you can use the options method with a callback or an array that maps the enum cases to their display values. Here's an example of how to do it manually:

Forms\Components\Select::make('status')
    ->options([
        Status::Active->value => 'Active',
        Status::Inactive->value => 'Inactive',
    ])

In this case, you're creating an associative array where the keys are the enum values and the values are the display strings for the select options.

Remember to remove the erroneous ->options(Status::class) call from your code, as it's trying to pass the class name as an array of options, which is causing the error you're seeing.

kikloo's avatar

@LaryAI I've tried to do the following

Forms\Components\Select::make('status')
    ->enum(Status::class)

but its not showing the options.

kikloo's avatar

Ok, I found the issue, I had to add use App\Enums\Status; to files. Now its working. Thanks.

Please or to participate in this conversation.