Laravel livewire在附加后看不到渲染更新
我有一个livewire组件在一个页面上呈现两个列表。我在左侧列表上有一个按钮,可以使用attach将该项添加到右侧列表(多对多)关系中。这是可行的,但正确的列表不会重新呈现。然后单击左侧列表中的过滤器时,右侧列表将重新呈现,显示新附加的项。在执行attach方法时,似乎没有调用render(),或者它正在进行另一次render调用以获取新关系?我还尝试从attach方法调用$this->render,但没有帮助Laravel livewire在附加后看不到渲染更新,laravel,render,laravel-livewire,Laravel,Render,Laravel Livewire,我有一个livewire组件在一个页面上呈现两个列表。我在左侧列表上有一个按钮,可以使用attach将该项添加到右侧列表(多对多)关系中。这是可行的,但正确的列表不会重新呈现。然后单击左侧列表中的过滤器时,右侧列表将重新呈现,显示新附加的项。在执行attach方法时,似乎没有调用render(),或者它正在进行另一次render调用以获取新关系?我还尝试从attach方法调用$this->render,但没有帮助 public function render() { $i
public function render()
{
$items = item::with('status')
->where(function($query){
$query->when(!empty($this->selectedStati), function ($query) {
$query->whereHas('status', function ($query) {
$query->whereIn('id', $this->selectedStati);
})->orWhereDoesntHave('status');
});
})
->get();
$testItems = $this->test->items;
//dd($testItems);
return view('livewire.items-source', [
'selectedStati' => $this->selectedStati,
'statuses' => $this->status,
'items' => $items,
'testItems' => $testItems
]);
}
public function filterStatus($id){
if (($key = array_search($id, $this->selectedStati)) !== false) {
unset($this->selectedStati[$key]);
} else {
$this->selectedStati[]=$id;
}
session(['status'=>$this->selectedStati]);
}
public function addToTest($id){
//attach the given item to the test
$this->test->items()->attach($id);
dd($this->test->items);
}
public function removeFromTest($id){
//detach the given item from the test
$this->test->items()->detach($id);
}
将项目附加到测试集合后,刷新模型以使用新数据对其重新水化,如
public function addToTest($id){
//attach the given item to the test
$this->test->items()->attach($id);
$this->test->refresh();
}
非常感谢你!我希望是这样简单的事情。我没有足够的声誉来支持你的答案,但这肯定是答案。很高兴听到这个,很好的编辑。在SolveWire上标记这个答案如果我将左列表和右列表分成两个独立的livewire组件,如何触发另一个组件刷新。例如,当我单击左侧的按钮“添加到右侧列表”时,右侧列表不会更新。我可以从一个组件调用另一个组件中的公共函数吗?使用事件,一旦加载项从左到右发射。有一个通过事件监听器重新启动的神奇指令,['refresh'=>'$refresh']