Filament 如何使用 Trait 在 (create,update) 后重定向到列表页面

97 阅读1分钟

要在 Filament v3 中创建或更新资源后重定向到列表页面,您可以在资源类中使用自定义特征。

Create a Custom Trait 创建自定义特征

<?php

namespace App\Traits;

trait RedirectIndex
{
    protected function getRedirectUrl(): string
    {
        return $this->getResource()::getUrl('index');
    }
}

Use the Trait in Your Filament Resource
在 filament 资源中使用 trait

class CreateProduct extends CreateRecord
{
    protected static string $resource = ProductResource::class;

   //add trait in your CreateRecord or UpdateRecord
    use \App\Traits\RedirectIndex; 
}