namespace AppHttpLivewireSurvey;
use LivewireComponent;
use AppModelsSection as SectionModel;
class Section extends Component
{
public $questionnaireId;
public $section;
public $currentSection = 0;
public $listeners = ['nextSection'];
public function nextSection()
{
$this->currentSection++;
$this->currentSection = $this->getSections($this->currentSection);
}
public function getSections($offset = 0)
{
$this->section = SectionModel::where('questionnaire_id', $this->questionnaireId)->offset($offset)->first();
}
public function mount($questionnaireId)
{
$this->questionnaireId = $questionnaireId;
$this->getSections();
}
public function getSectionsProperty()
{
return $this->section;
}
}
This is my componentOne.php
public function triggerNextSection()
{
$this->emit('nextSection');
}
This is component-one.blade.php
<button wire:click="triggerNextSection"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"> Continue
</button>
while click on the button continue, $currentSection value is increased by 1.
Same way I used this button and emit this event in componentTwo, Here not incrementing the value of $currentSection.
Can anyone please help how should I increment this varible value?
I tried to emit an event with passing parameters