How to change resource form opened by edit action on a relationmanager

This is going to get confusing but let me try. I have 2 models Degree and Programs, these share a many to many relationship that includes pivot table data. These tables are also accessed from a different (legacy) application so the pivot table needed to have it's own id field. So I made a model and resource in filament called DegreeProgram. I have setup the forms etc for DegreeProgram in filament but it looks ugly having it on the navigation menu. Within the DegreeResource I have a relationmanager for programs and would like to have the create and edit actions from that relation manager redirected to the create and edit forms for the DegreeProgramResource instead, while leaving the attach/deteach actions link the the original relationship. I tried editing the relationship manager to use the other form but that threw this error
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given.
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given.
So then I tried mutating the data being sent to the form like this
->mutateRecordDataUsing(fn (array $data): array => [
$data = DegreeProgram::where('program_id', $data['program_id'])->where('degree_id', $data['degree_id'])->first(),
]),
->mutateRecordDataUsing(fn (array $data): array => [
$data = DegreeProgram::where('program_id', $data['program_id'])->where('degree_id', $data['degree_id'])->first(),
]),
but that throws this error
Call to a member function getResults() on null
Call to a member function getResults() on null
Does anyone have any other ideas?
1 Reply
bardolf_6969
bardolf_6969OP2mo ago
So rather than customizing the predefined edit to suit my needs I created a custom edit action to replace it.
Want results from more Discord servers?
Add your server