Last active
March 16, 2023 03:19
-
-
Save codemonkey76/d9496ccff1a469ad9e4bab950f353d28 to your computer and use it in GitHub Desktop.
Using wire:model on nested component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
@foreach($this->options as $option) | |
<div wire:click="optionSelected('{{$option}}')">{{ $option }}</div> | |
@endforeach | |
<div>{{ $this->selectedOption }}</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire\Controls; | |
use Livewire\Component; | |
class Accordion extends Component | |
{ | |
protected $listeners = ['refreshAccordion' => '$refresh']; | |
public $options; | |
public $selectedOption; | |
public function booted() | |
{ | |
$this->options = ['foo', 'bar', 'baz']; | |
} | |
public function optionSelected($option) | |
{ | |
$this->selectedOption = $option; | |
} | |
public function render() | |
{ | |
return view('livewire.controls.accordion'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<livewire:controls.accordion | |
wire:model="selectedOption" | |
/> | |
<div>@json($selectedOption)</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire\Controls; | |
use Livewire\Component; | |
class Parent extends Component | |
{ | |
public $selectedOption; | |
public function render() | |
{ | |
return view('livewire.parent'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment