Use ID on newly created Model from ->createOptionAction

For the life of me i can't seem to figure this out.

I have a select form that uses ->createOptionForm so that i can create a new one (company in this case) as well. I want to perform some actions on it after creating like i can do with the afterCreate() method on my create page.

So far i have:

->createOptionForm(Company::getForm())
                                ->createOptionAction(function ($action) {
                                    $action->mutateFormDataUsing(function ($data) {
                                        $data['team_id'] = Filament::getTenant()->id;
                                        $data['normalized_title'] = NameNormalizer::normalize($data['title']);
                                        $data['client_number'] = Company::generateUniqueClientNumber();
                                        $data['street'] = ucwords(strtolower($data['street']));
                                        $data['town'] = ucwords(strtolower($data['town']));
                                        $data['postbox_town'] = ucwords(strtolower($data['postbox_town']));
                                        return $data;
                                        });
                                    $action->after(function ($data) {
                                        if(!condition) :
                                            // Do something with the created company, like in afterCreate()
                                        endif;
                                    });


No matter what i try my Model in the ->after() method is always null ($action->after(function ($data, Model $record) {).
Was this page helpful?