How to set $record for Custom Action

I have an action that i want to easily use throughout my app and I am having issues figuring out how to set the record that is being used. Its working fine as. a table action as the record is passed automatically and even fine as a form action is a Property record, but lets say I have another form that is a User record that has a property relationship. I want to be able to use this action there, but unfortuantely i get a type mismatch issue as its trying to use the User model and not the Property model. Unfortunately its not as simple as setting ->record() on the action. This is what my current action looks like (simplified a bit):
<?php

namespace App\Actions\Filament\Forms;

use App\Models\Property;
use Filament\Forms\Components\Actions\Action;
use Illuminate\Contracts\View\View;

class ViewPropertyAction extends Action
{
    protected function setUp(): void
    {
        $this
            ->label('View')
            ->modalContent(fn (Property $record): View => view(
                'forms.property',
                ['record' => $record],
            ))
            ->extraModalFooterActions([
                \Filament\Tables\Actions\Action::make('edit')
                    ->label('Edit Property')
                    ->url(function ($record) {
                        //return route('properties.edit', $this->modalRecord ? $this->modalRecord->id : $record->id);
                        return route('properties.edit', $record->id);
                    })
                    ->color('primary')
                    ->button(),
            ]);
    }
}
and I just call it with
ViewPropertyAction::make('view_property')
. Wish i could just do
ViewPropertyAction::make('view_property')->record($model)
or whatever. Any suggestions?
Was this page helpful?