Closed raphaelmsr closed 5 years ago
Hi! Thanks for using my package.
This package temporarily stores each Step data as an Array, not a storage Model. So you can use the following methods to solve:
Suppose there are now two Steps NameStep
and EmailStep
.
First, don't set the Model for all Steps, but don't use the last one (is NameStep
):
public function model(Request $request)
{
//
}
public function saveData(Request $request, $data = null, $model = null)
{
//
}
Next, receive all the data in the last Step and save Model (is EmailStep
):
public function model(Request $request)
{
return new User();
}
public function saveData(Request $request, $data = null, $model = null)
{
$data = $this->wizard->stepRepo()->original()->reduce(function ($carry, $step) {
return array_merge($carry, $step->data());
}, []);
$model->fill($data)->save();
}
Give it a try!
GREAT ! That works awesome. Maybe add this to the README, your package is fire. Now two more things, if you dont mind. First It doesnt save the data when I hit the back button; back functions as RESET, which would be a nice feature but I would rather just go back in history and keep the input data. Second, how can I show in the EmailStep blade file, information from NameStep. Can I reach to $this->wizard->stepRepo() within blade ?
EDIT : To pass data, I use session()->all() since I store in Session, not in DB. Same for the back button! Thanks!
getRepo
method to Step. You can use the $step->getRepo()->prev()->data('name')
, $step->getRepo()->next()->data()
, $step->getRepo()->first()->data('email')
to get other step data on in the Blade. Detailed reference https://github.com/ycs77/laravel-wizard/blob/master/src/StepRepository.php.$step->getRepo()->prev()->data('name')
is the data retrieved from the session. Clear the data in the session when the Wizard executes to done.Amazing, was doing this
$session_info = isset(session()->all()["laravel_wizard"]) ? session()->all()["laravel_wizard"]["account"]["step_account"] : [];
But I guess $step->getRepo()->prev()->data('name')
takes care of all of this. Such great reactivity !
Happy use it! 😃
Hi, thanks for your reactivity for the udpate! I'm using your package and I need to have data from the 1st step shown in the 2nd step; how can I achieve that. Also my model is
new User;
, so I how do define my model in the next steps ? Since its not new and its to add more to the same - should I simply putnew User;
again ?