Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

robertp1980's avatar

Filament edit action on custom model inside a table?

How to make an edit action for a another model inside a table?

                EditAction::make('editOtherModel')
                    ->label('Edit other Model')
                    ->model(MyOtherModel::class)
                    ->record(MyOtherModel::find(4499))
                    ->form(static::MyOtherModelFormComponent())
                    ->slideOver(),

It don't works. The Form ist empty.

When i try to make a fillForm(), i get an error with my SelectField that has a relationship().

0 likes
5 replies
aurawindsurfing's avatar

Use Action instead of predefined EditAction

Action::make('editOtherModel')
                    ->label('Edit other Model')
                    ->model(MyOtherModel::class)
                    ->record(MyOtherModel::find(4499))
                    ->form(static::MyOtherModelFormComponent())
                    ->slideOver()
robertp1980's avatar

@aurawindsurfing I tried it, but also do not works. Everytime i use a ->relationship() in my select field, i get

"Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /var/www/html/vendor/filament/forms/src/Components/Select.php"

aurawindsurfing's avatar

To be honest your action looks nothing like mine. I never use ->model or ->record

I always access them in my ->action callback

Your error clearly says that it gets no relation, is it declared on the model both ways?

And just to clarify you want to select a record in the table and edit its related model correct?

robertp1980's avatar

Ok, i try it better to explain.

I have a resource Table, with listing for example all ModelA, when i now try to EditAction or Action ModelA, everything works fine. No problems etc.

But i have a Table, with ModelsB, when i make now an Action to edit ModelA inside this Table, it doesen work. I found out, that he tries to load the relationship definition from ModelA, instead from ModelB.

I try to create a Table, where i have all Listings etc, but i would like also to create an Action to edit for example, related Models etc.

Like, i have a Listing of Books, and i want also a button inside the Row, where i can edit the Author of the Book "in Modal".

aurawindsurfing's avatar

Think of ->action as a normal function where you can do whatever you want.

So in your case it will be simply:

->action(fn ($record) => $record->save([’author’ => $author]);

As long as you have relations defined you can access it from anywhere.

Sorry! Im on mobile!

Please or to participate in this conversation.