Filament: show a viewAction on a different model that we are in

2 days ago 1
ARTICLE AD BOX

In using Filament 5 in laravel 12. I have a vehicle which can have several damages. In the viewVehicle page i've made a custom view to show all the damages on a map

Section::make(__('Damage map')) ->schema([ ViewEntry::make('damage_map') ->hiddenLabel() ->view('filament.components.vehicle-damage-map') ->viewData(fn (Vehicle $record): array => [ 'imageUrl' => VehicleDamageMap::getVehicleTypeImageUrl($record), 'points' => VehicleDamageMap::getDamagePoints($record), ]) ->columnSpanFull(), ]) ->columnSpanFull() ->columns(12),

the blade just loop the points, shows them as a dot which i made as an action

@foreach ($points as $point) {{ ($this->viewDamageAction)(['record' => $point]) }} @endforeach

And here we have the problem, i've tried several methods, but the view action, since it's done inside the VehicleView always gets the data of the vehicle to fill the form, ignoring the fillForm method

return ViewAction::make('viewDamage') ->fillForm(function ($arguments, $form): array { $record = VehicleDamage::find($arguments['record']['id']); return $record->toArray(); }) ->schema(function ($schema, $arguments) { return VehicleDamageInfolist::configure($schema); });

So what I got is to have the schema from the damage, with all the correct fields of the damage info list, but the data shown are those of the vehicle.

What am I doing wrong?

Read Entire Article