Hi all!
I would like to build a Seatmap with Livewire. But the following Scenario is not working as expected.
Based on the Seat Status ($seat->status
) I’m rendering the corresponding Livewire Component.
<?php
namespace App\Http\Livewire\Seatplan;
use App\Seat;
use Livewire\Component;
class Row extends Component
{
public $row;
public $y_pos;
public $y;
protected $listeners = ['rowUpdated'];
public function mount($row)
{
$this->row = $row;
$this->y_pos = $this->row->first()->y_pos;
$this->y = $this->row->first()->y;
}
public function getWayProperty()
{
return $this->row->count() === $this->row->where('way', true)->count();
}
public function rowUpdated()
{
$this->row = Seat::where('y_pos', $this->y_pos)->get();
$this->y_pos = $this->row->first()->y_pos;
$this->y = $this->row->first()->y;
}
public function render()
{
return view('livewire.seatplan.row');
}
}
<div class="row justify-content-start flex-nowrap">
<div class="col-2 text-nowrap">{{ $this->way ? null : "Row $y" }}</div>
<div class="col-5 d-flex flex-nowrap">
@foreach($row as $seat)
@livewire("seatplan.seat.$seat->status", ["seat" => $seat], key($seat->id))
@endforeach
</div>
</div>
Now, when I’m emitting the rowUpdated
Event, the Text based on $this->way
is changing correctly. But the nested Livewire Component seatplan.seat.$seat->status
keeps rendering the “old” Status Component.
For Example:
1 - Status: foo - Livewire Component foo is rendered
2 - Status: updates to bar - Livewire Component foo is still rendered
Thanks for your help!
Regards
Fabian