ATR22's avatar
Level 1

Add some extra info top of Edit page in Filament

Hi. I have a Documents resource at admin side, I want admin see the docs user sent and if he confirm it choose Status and submit it. I mean, I don't want all columns of document be changable at Edit form, I want admin just see info and pics that user sent (not like inputs, like text and pics) and just one inptut for admin to confirm that.

I read all docs, I'm realy confusing, I even don't know how I should search for my answer, Filament is new for me.

I really would be thankful if you tell me how i should edit "Pages\EditDocument" file for that?

0 likes
3 replies
ATR22's avatar
Level 1

I found out that I should use custom actions in my table.

I write this code:

It doesnt work. It shows just infolist part, not the form until when I comment out the infolists then form will be showed. It deasnt show both.

what I should to do? I want admin see some info from user then submit a form based on that info.

Any help??

jaseofspades88's avatar
Level 51

In EditDocument you need to include the following method.

    protected function getHeaderActions(): array
    {
        return [
            \Filament\Actions\Action::make()
                ->form([
                    //fields here
                ])
                ->action(function (array $data) {
                    //action here
                }),
        ];
    }

This will give you an action button at the top and you can have it do whatever you need it to... just like ordinary actions in Filament. Notice - this is NOT a table action, it's a page action class.

I would actually recommend you don't use an EditDocument page for displaying information, if you read the documentation, I know... a big ask... here: https://filamentphp.com/docs/3.x/panels/resources/viewing-records, which will tell you how to create a simple ViewDocument page.

That too can have actions at the top of the page and it will be much better than using an edit page to view information.

1 like
getupkid203's avatar

For Filament 3.x:

If I'm understanding your problem correctly, you're looking for a way to render some infolist content at the top of an Edit page?

I think I've worked this out. Took a bit of digging. But basically an EditRecord page inherits Filament\Pages\BasePage which includes the InteractsWithInfolists trait. Same as a ViewRecord page.

So I took a look at the ViewRecord page to see what it's doing to support infolists. Pretty simple actually, it has 2 extra methods:

public function infolist(Infolist $infolist): Infolist
    {
        return static::getResource()::infolist($infolist);
    }

    protected function makeInfolist(): Infolist
    {
        return parent::makeInfolist()
            ->record($this->getRecord())
            ->columns($this->hasInlineLabels() ? 1 : 2)
            ->inlineLabel($this->hasInlineLabels());
    }

So, the first thing to do would be to add these two methods (and import Infolist) to your Edit{Something}.php page.

For me, I'm using EditQuote.php coz I have a quoting system.

// ...
use Filament\Infolists\Infolist;
// ...

class EditQuote extends EditRecord
{

    // ....

    public function infolist(Infolist $infolist): Infolist
    {
        return static::getResource()::infolist($infolist);
    }

    protected function makeInfolist(): Infolist
    {
        return parent::makeInfolist()
            ->record($this->getRecord())
            ->columns($this->hasInlineLabels() ? 1 : 2)
            ->inlineLabel($this->hasInlineLabels());
    }

    // ....
}

With the infolist() method, you can see that by default it's pulling the infolist from the Resource class. You can choose to keep this and build your infolist in the Resource class OR you could override the infolist() method and build your infolist() inside this class.

Now, to render the Infolist, you've got a couple of options.

  1. Creating a custom view page and copying over all the contents of resources/views/resources/pages/edit-record.blade.php into your custom view and then rendering it. By copying over all the contents of edit-record.blade.php you're making sure that the edit page functionality continues to work as expected:

/path/to/your/custom-view.blade.php

  1. Publish the filament view files (not always recommended) and then just add {{ $this->infolist }} to the edit-record.blade.php (pretty much the same as the above). https://filamentphp.com/docs/3.x/support/style-customization#publishing-blade-views

Optional: Create your own EditRecord class that extends Filament's EditRecord and add the above Infolist methods so and update all your Edit{Something}.php pages to extend your new EditRecord class. That way all your Edit pages will inherit the Infolist functionality.

Please or to participate in this conversation.