createOptionForm is not saving the created record

Hello. I have a relatively complex form to create dossiers. One on the fields of that dossier is person_id (decedent_id) which comes from the resource people. I have used the createOptionForm to have the possibility to create a new person in modal form without leaving the dossier create form. Everything looks fine, but it gives an error: Select field [data.decedent_id] must have a [createOptionUsing()] closure set. If I use that createOptionUsing like this:
->createOptionUsing( function (Get $get) {
$get('id');
})
->createOptionUsing( function (Get $get) {
$get('id');
})
it does nothing. I mean, it does NOT CREATE the new person record (thowing no errors at all). I do not have a relationship between dossier and people for just one field of decedent person. Is a relationship a MUST-HAVE for a modal create form with createOptionForm? Any ideas of how to get along this? Thanks. I do not write all the code, because it is too long, but the main part is:
Select::make('decedent_id')
->label(__('decedent_id'))
->required()
->options(DB::table('people')->select('id', DB::raw("CONCAT(people.full_name,' (',people.doc_num,') ',COALESCE(DATE_FORMAT(people.date_of_death,'%d-%b-%Y', 'es_es'),'sin fecha fallecimiento')) AS full_name"))->get()->pluck('full_name', 'id'))

Select::make('decedent_id')
->label(__('decedent_id'))
->required()
->options(DB::table('people')->select('id', DB::raw("CONCAT(people.full_name,' (',people.doc_num,') ',COALESCE(DATE_FORMAT(people.date_of_death,'%d-%b-%Y', 'es_es'),'sin fecha fallecimiento')) AS full_name"))->get()->pluck('full_name', 'id'))

Any help will be highly appreciated. I am really stuck here. Tks.
No description
No description
2 Replies
xy
xy11mo ago
#✅┊rules please format your post so its more readable Also you're using createOptionUsing wrong. It expects a closure (which is what the Laravel error is telling you). Example:
->createOptionUsing(function ($data) {
$post = new Post();
$post->fill($data);
$post->save();
return $post->id;
})
->createOptionUsing(function ($data) {
$post = new Post();
$post->fill($data);
$post->save();
return $post->id;
})
Albert Lens
Albert Lens11mo ago
Thank you very much!!! It works perfectly. I am sorry but I did not find anything about createOptionUsing() in the documentation. Not a single example or explanation. Also, I try to format my code as much as I can. I always use backticks, but it never appears in color and it does not always look well tabbed and fine. I use backticks and insert the code there. I never tried to begin with pph. I'll keep on trying my best. Example;
Select::make('decedent_id')
->label(__('decedent_id_title'))
->required()
->options(DB::table('people')->select('id', DB::raw("CONCAT(people.full_name,' (',people.doc_num,') ',COALESCE(DATE_FORMAT(people.date_of_death,'%d-%b-%Y', 'es_es'),'sin fecha fallecimiento')) AS full_name"))->get()->pluck('full_name', 'id'))
->searchable()
->live()
->columnSpan(4)
Select::make('decedent_id')
->label(__('decedent_id_title'))
->required()
->options(DB::table('people')->select('id', DB::raw("CONCAT(people.full_name,' (',people.doc_num,') ',COALESCE(DATE_FORMAT(people.date_of_death,'%d-%b-%Y', 'es_es'),'sin fecha fallecimiento')) AS full_name"))->get()->pluck('full_name', 'id'))
->searchable()
->live()
->columnSpan(4)