wizard step create record on first step

on a wizard on create i would like to create record on first step i see i can call ->afterValidation(function(?Model $record,$state){ so i can create record .. but i don't know to set it for calling it in the second record
2 Replies
toeknee
toeknee2y ago
You can use session or closure setters / gettings.
->afterValidation(function(?Model $record,$state,Closure $get, Closure $set){
$record = Model::create([]);
$set('id', $record->id);
})
->afterValidation(function(?Model $record,$state,Closure $get, Closure $set){
$record = Model::create([]);
$set('id', $record->id);
})
But be careful as you will need to override the native submit function of the wizard as it will try and create it again when you submit it. This also breaks going back natively, so you'd need to condition that too or prevent going backwards.
marco76tv
marco76tvOP2y ago
in the second step i must put
if($record==null){
$record=Model::find($get('id'));
}

if($record==null){
$record=Model::find($get('id'));
}

Did you find this page helpful?