How can we use session to keep step wizard persistent even after reloading (refreshing) the user browser?
Hello instead of asking another similar question I want to add mine. I use Livewire to build step form to create a resource but when I am in step 1 if I reload the browser it returns to step 0 (Step 0 show a Create Button that invite users to begin the process . The code is listed below :
Data binding in Livewire Controller
class Products extends Component
{
public $currentStep = 0;
public $total_steps = 3;
// others attributes
public function render()
{
return view('livewire.products.index');
}
public function incrementSteps()
{
if ($this->currentStep < $this->total_steps) {
$this->currentStep++;
}
}
public function decrementSteps()
{
if ($this->currentStep > 0) {
$this->currentStep--;
}
}
}
I only included steps 0 and step 1 because I told myself before dealing with the other steps it would be better to deal with the loss of step 1 which returns to step 0 after reloading the browser. I think in that case we could use session but how can I integrate it in this situation?
class Products extends Component
{
public $currentStep = 0;
public $total_steps = 3;
// others attributes
public function mount(){
if(isset(session('currentStep')){
$this->currentStep = session('currentStep')
}
}
public function incrementSteps()
{
if ($this->currentStep < $this->total_steps) {
$this->currentStep++;
session('currentStep', $this->currentStep);
}
}