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

JohnDivam @johndivam

About: Focus on delivering high-quality solutions. #Laravel . Wye Team

Joined:
Jul 11, 2023

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

Publish Date: Aug 22 '24
7 2

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

Comments 2 total

  • Eduardo Antonio Almanza Pérez
    Eduardo Antonio Almanza PérezOct 18, 2024

    Excelente

  • pasteldenata
    pasteldenataApr 6, 2025

    Thank you so much, I've been looking for this for such a long time.
    Done in an elegant way!
    How come this isn't part of the mainstream release of Filament ?...

Add comment