Home  >  Article  >  Backend Development  >  Filament How to redirect to list page after (create,update) using Trait

Filament How to redirect to list page after (create,update) using Trait

王林
王林Original
2024-08-22 20:31:07543browse

Filament How to redirect to list page after (create,update) using Trait

To redirect to the list page after creating or updating a resource in Filament v3, you can use a custom trait in your resource class .

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

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

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

The above is the detailed content of Filament How to redirect to list page after (create,update) using Trait. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn