F
Filament7mo ago
terumi

Passing another Model to an Action instead of that that the Table iterates through

I know what I've written sounds convoluted but what I basically want to achieve is this: I have a table that takes a "fake" model that derives from a view-table in my database (because of "impossible" relations, max, mins etc). I display the data of the fake model "viewASDs" and on each row I have an edit function by which I want to edit the corresponding "ASD" model. I've set up the record() method of the table ( ->record(fn() => ASD::find($record->id)) ) but that seems to refer to something else. Whenever I try to call mutateRecordDataUsing(), using() etc, the methods take as an argument the viewASD model. Is there a way to perform actions to another model than the one that the table iterates through?
1 Reply
Majid Al Zariey
Majid Al Zariey7mo ago
I had to do exactly the same thing, the record will be overridden by the table record after you set your record You could make a Action class and override the record function
class CustomAction extends Action
{
public function record(Closure|null|Model $record): static
{
if ($record instanceof YourClass) {
return parent::record($record);
}
return $this;
}

}
class CustomAction extends Action
{
public function record(Closure|null|Model $record): static
{
if ($record instanceof YourClass) {
return parent::record($record);
}
return $this;
}

}
Want results from more Discord servers?
Add your server