DEV Community

JohnDivam
JohnDivam

Posted on

6 1

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');
    }
}

Enter fullscreen mode Exit fullscreen mode

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; 
}

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
almanza023 profile image
Eduardo Antonio Almanza Pérez

Excelente

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more