How to get the id of the data created using createOptionUsing()

I want to add a data in the pivot table after creating the data. Now I don't have the access on the id of the newly created data. How can I do this Forms\Components\Select::make('process_owner') ->label('Process Owner') ->relationship('processowner','name', fn (Builder $query) => $query->whereHas('companies', fn ($query) => $query->where('company_id', Auth::user()->current_company_id))) ->preload() ->searchable() ->createOptionForm([ Forms\Components\TextInput::make('name') ->required(), Forms\Components\TextInput::make('email') ->required(), Hidden::make('password') ->required() ->default(Hash::make('password')) ->disabled(), Hidden::make('current_company_id') ->default( Auth::user()->current_company_id) ]) ->createOptionUsing(function(array $data) { ),
Solution:
```php ->createOptionUsing(function(array $data) { dd($data); // Create manually your new row in your pivot model and access to $model $model = Model::create($data);...
Jump to solution
2 Replies
Solution
Antoine
Antoine14mo ago
->createOptionUsing(function(array $data) {
dd($data);
// Create manually your new row in your pivot model and access to $model
$model = Model::create($data);
return $model->id;
})
->createOptionUsing(function(array $data) {
dd($data);
// Create manually your new row in your pivot model and access to $model
$model = Model::create($data);
return $model->id;
})
Zyel
Zyel14mo ago
error catch
Want results from more Discord servers?
Add your server