Relationship not saved when using createOptionUsing on Select input

Hi guys, I am trying to create subject via select input with createOptionForm. Inside that form is another relationship (seller), that is not saved when I chain createOptionUsing method. When I remove that method seller relationship is saved correctly, but I also need to save broker_id (user) to that subject, thats why I use createOptionUsing method. Can you help me?

Forms\Components\Select::make('subject_id')
    ->label(__('Subject'))
    ->relationship('subject', 'name')
    ->createOptionForm(static::getSubjectFields())
    ->createOptionUsing(function (array $data, Forms\Get $get): int {
        $user = User::find($get('broker_id')) ?? auth()->user();

        return $user->subjects()->create($data)->getKey();
    })
    ->saveRelationshipsUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    })
    ->saveRelationshipsBeforeChildrenUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    }),
Was this page helpful?