HintAction Adding to Select Element

Hello - I'm wondering if anyone has ever had an issue using a hintAction to add to a select element. Here is the relevant code:

Select::make('meal_id')
->label('Meal')
->required()
->searchable()
->reactive()
->options(function () use ($order) {
    $meals = Meal::where('kitchen_id', $order->provider_id)
        ->get();

    $array = [];

    foreach ($meals as $meal) {
        $array[$meal->id] = $meal->name . ' ($' . $meal->price . ')';
        if (isset($meal->servings)) {
            $array[$meal->id] .= ' (' . $meal->servings . ')';
        }
    }

    return $array;
})
->hintAction(function ($set) use ($order) {
    return Action::make('createCustomRestaurantMeal')
        ->label('Custom Selection')
        ->form([
            TextInput::make('name')
                ->required()
                ->maxLength(100)
        ])
        ->action(function ($data) use ($order, $set) {
            $meal = Meal::create([
                'name' => $data['name'],
                'kitchen_id' => $order->provider_id,
                'approved' => false,
            ]);

            $set('meal_id', $meal);

            $kitchenUsers = $order->getKitchenUsersForNotification();

            foreach ($kitchenUsers as $user) {
                Notification::make()
                    ->title('New Menu Request')
                    ->body('A custom menu request has been submitted.')
                    ->actions([
                        ActionsAction::make('view')
                            ->url(route('filament.admin.resources.meal-approvals.index'), shouldOpenInNewTab: true)
                    ])
                    ->sendToDatabase($user);
            }
        });
})


Two issues:
  1. It is not setting the meal_id after creating the meal in the hintAction
  2. After searching for and selecting the meal, it disappears
I feel like these two issues are related (#1 might just happen quickly enough that I don't see it selected initially)
Solution
Of course the answer was in the docs... ->createOptionUsing() needs to return the ID of the newly created model
Was this page helpful?