Access record data

Is it possible to access the data of a record before returning the form?
public static function form(Form $form): Form
{
// Here I would like to access the record data before returning the form

return $form
->columns(1)
->schema(Product::getForm());
}
public static function form(Form $form): Form
{
// Here I would like to access the record data before returning the form

return $form
->columns(1)
->schema(Product::getForm());
}
4 Replies
Eugen Pașca
Eugen Pașca11mo ago
you could inject the Component into your required method in your form ( https://filamentphp.com/docs/3.x/forms/advanced#injecting-the-current-livewire-component-instance ) Or if you really need to access the record data, i managed to do that including the form method directly into the view/edit Pages. there it would not be static anymore so it should have access to the record
public function form(Form $form): Form
{
// Here I would like to access the record data before returning the form
$record = $this->getRecord();
return $form
->columns(1)
->schema(Product::getForm());
}
public function form(Form $form): Form
{
// Here I would like to access the record data before returning the form
$record = $this->getRecord();
return $form
->columns(1)
->schema(Product::getForm());
}
Matthew
Matthew11mo ago
You can use mutateFormDataBeforeCreate if you want This wont be possible inthe create page, as there is no record (therefore null)
Eugen Pașca
Eugen Pașca10mo ago
Yeah, you are right, I was thinking that by asking to access the data of a record, there must have been a record to begin with, like on the view/edit.
Matthew
Matthew10mo ago
yeah indeeed if you want to get form data you could use Getter/Set
Want results from more Discord servers?
Add your server