createOptionUsing() doesn't select new value

Hello everyone,

I'm pretty confused because I don't understand where is my error. I have this Select in a Form :

Select::make('filter')
  ->options(Filter::where('user_id', auth()->user()->id)
    ->pluck('name', 'id'))
  ->createOptionForm([
      TextInput::make('name')
          ->required(),
  ])
  ->createOptionUsing(function($data) {
      $name = $data['name'];
      $filter = Filter::create([
          'user_id' => auth()->user()->id,
          'name' => $name,
      ]);
      return $filter->id;
  })
  ->afterStateUpdated(...)
  ->live()

When I submit my modal, I return the id of my model that I have just created. I debugged
$filter->id
with
dd()
before returning it and it exists as well as my row in the database. But it returns null in my component after submit.

However, if I return a value manually from an already existing line like:
return 1;
It selects it well.

I tried on another form and I still have the same problem when I create a model row.

Did I do something wrong? Or is it another problem? I think I am returning the model before it is created in the Select options, is there a method for resolve this?
Was this page helpful?