Search code examples
laravellaravel-livewire

Nesting Components Livewire


I have a run Table that shows this

ID   Name   Details  (modal button)

Whenever modal button is clicked, I wanted it to call another livewire component, however, I need to pass the ID of the existing table list that I have

Here is my sub component whenever the modal button is clicked.

public $run;

public function mount($id) 
{
    $this->run = $id;    
}

public function render()
{
    $runs = Runners_List::where('run_list_id', $this->run)->get();

    return view('livewire.runners-list', [
        'runs' => $runs,
    ]);
}

And in my modal, I have this

@livewire('runners-list', ['id' => $viewRun])

$viewRun is the ID from my main components listing or the ID per row

I need help how to pass the $viewRun (or ID from my main component) to the sub component above.

is this even possible? Thanks

UPDATE::

if I replace $viewRun with a value, it's able to fetch the data.

@livewire('runners-list', ['id' =>  $viewRun ] ) 

Solution

  • got it to work

    <livewire:runners-list :id="$viewRun" :key="$viewRun">