© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
13 replies
bwurtz999

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);
            }
        });
})
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
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()
->createOptionUsing()
needs to return the ID of the newly created model
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Select Element - Without model
FilamentFFilament / ❓┊help
2y ago
adding user-menu.start element
FilamentFFilament / ❓┊help
3y ago
ManyToMany Relationship via Select element
FilamentFFilament / ❓┊help
2y ago
ViewRecord - Adding Select Dropdown
FilamentFFilament / ❓┊help
2y ago