F
Filament16mo ago
Pasteko

Enum with form->select

Why is it working for table->TextColumn but not for form->select?
<?php

namespace App\Enums;
use Filament\Support\Contracts\HasLabel;

enum TitreEnum: int implements HasLabel
{
case M = 0;
case MME = 1;

public function getLabel(): ?string
{
return match ($this) {
self::M => 'M.',
self::MME => 'Mme',
};
}
}
<?php

namespace App\Enums;
use Filament\Support\Contracts\HasLabel;

enum TitreEnum: int implements HasLabel
{
case M = 0;
case MME = 1;

public function getLabel(): ?string
{
return match ($this) {
self::M => 'M.',
self::MME => 'Mme',
};
}
}
Filament\Forms\Components\Select::getOptions(): Return value must be of type array, string returned
Solution:
OK a final review before we debug this: 1- is the enum class included in the resource file? use App\Enums\TitreEnum 2- is the enum class included in the model file?...
Jump to solution
8 Replies
SoraKeyheart
SoraKeyheart16mo ago
In your model, make sure it's like this: protected $casts = [ 'column_name' => TitreEnum::class, ]
Pasteko
PastekoOP16mo ago
Yes I have this in the model and it works fine for table->TextColumn
protected $casts = [
'title' => TitreEnum::class,
];
protected $casts = [
'title' => TitreEnum::class,
];
SoraKeyheart
SoraKeyheart16mo ago
Please show the Select code block
Pasteko
PastekoOP16mo ago
public static function form(Form $form): Form
{
return $form
->schema([
Group::make()
->relationship('details')
->schema([
Select::make('title')
->options(TitreEnum::class)
->label('Titre'),
TextInput::make('last_name')->label('Nom'),
TextInput::make('first_name')->label('Prénom'),
]),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Group::make()
->relationship('details')
->schema([
Select::make('title')
->options(TitreEnum::class)
->label('Titre'),
TextInput::make('last_name')->label('Nom'),
TextInput::make('first_name')->label('Prénom'),
]),
]);
}
SoraKeyheart
SoraKeyheart16mo ago
Try moving your select outside of relationship schema. I don't believe relationships have schemas. Sorry I miss read the code, try removing relationship
Pasteko
PastekoOP16mo ago
Same error : Filament\Forms\Components\Select::getOptions(): Return value must be of type array, string returned
Solution
SoraKeyheart
SoraKeyheart16mo ago
OK a final review before we debug this: 1- is the enum class included in the resource file? use App\Enums\TitreEnum 2- is the enum class included in the model file? 3- is it setup in protected $casts?
Pasteko
PastekoOP16mo ago
Thank you 1 did the trick 🙂
Want results from more Discord servers?
Add your server