我可以使用 Filament (v2) 操作来刷新整个页面,或者至少更新导航徽章吗?
我有一个食谱表,并且在该食谱表上有一个单一操作,它将食谱添加到菜单中。
我有一个菜单资源,其中有一个导航徽章,显示该菜单中的食谱数量。
但是当我单击操作将菜谱添加到菜单时,它不会立即更新导航徽章。我必须刷新浏览器中的页面才能看到更新后的导航徽章。
有什么方法可以让操作成为 react 性的,以便它更新整个页面吗?或者甚至是一种让操作触发导航徽章刷新的方法?
最佳答案
您可以添加重定向到操作
class CreateProduct extends CreateRecord
{
protected static string $resource = ProductResource::class;
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
}
或者你可以使用livewire(生命周期 Hook )
https://filamentphp.com/docs/2.x/admin/resources/editing-records#lifecycle-hooks
它看起来像这样
->actions([
Tables\Actions\EditAction::make()
->after(function (Component $livewire) {
$livewire->dispatch('refreshProducts');
}),
我们需要监听事件并刷新页面。 (在 editFileName.php 中)
use Livewire\Attributes\On;
class EditProduct extends EditRecord
{
// ...
#[On('refreshProducts')]
public function refresh(): void
{
}
}
关于laravel - 是否可以使灯丝(版本 2) Action 具有反应性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77041351/