How to modify a model before form fill?

Hello. I have a laravel form I'm trying to convert into Filament. Before loading the create page I would reach out to an external database for info about the user. Is this possible to do with a filament resource?
public function fillApplicationPersonalInfo(): static
{
$this->id = $this->user->id ?? auth()->user()->id;
$results = $this->getExternalUserPersonalInfo();
$this->setData($results);

return $this;
}
public function fillApplicationPersonalInfo(): static
{
$this->id = $this->user->id ?? auth()->user()->id;
$results = $this->getExternalUserPersonalInfo();
$this->setData($results);

return $this;
}
This function sets attributes on my Application model so I have access to them on the create page.
Solution:
In the View page of the resource you can call the function above from the mount method. ``` class ViewModel extends ViewRecord { protected static string $resource = ModelResource::class;...
Jump to solution
1 Reply
Solution
Horizons
Horizons9mo ago
In the View page of the resource you can call the function above from the mount method.
class ViewModel extends ViewRecord
{
protected static string $resource = ModelResource::class;

public Model|int|string|null $record = null;

public function mount(int|string $record): void
{
$this->record = Model::find($record);
$this->record->fillApplicationPersonalInfo();
$this->fillForm();
}
}
class ViewModel extends ViewRecord
{
protected static string $resource = ModelResource::class;

public Model|int|string|null $record = null;

public function mount(int|string $record): void
{
$this->record = Model::find($record);
$this->record->fillApplicationPersonalInfo();
$this->fillForm();
}
}