F
Filament7mo ago
CGM

Prefill Resource Create Fields from beforeFill()?

I'm looking to prefill some resource fields (when Creating a resource) using values from a cookie. Is the beforeFill() Life Cycle hook an appropriate place to do this? If so, how do I actually interact with the $form from inside this hook? Is there another more appropriate place to do this?
6 Replies
CGM
CGMOP7mo ago
Digging in still, I was hoping this might work:
protected function mutateFormDataBeforeFill(array $data): array
{
// dump($data);
return $data;
}
}
protected function mutateFormDataBeforeFill(array $data): array
{
// dump($data);
return $data;
}
}
but I think this may only be for editing records? Is the only place to modify the initial values for a field the 'default()' method?
LeandroFerreira
LeandroFerreira7mo ago
Yes, use default()
CGM
CGMOP7mo ago
Thank you Leandro. This also just solved the other part of my issue. The fact this is a livewire component made everything else much cleaner/easier too.
public function mount(): void {
// in Create<Resource>.php
}
public function mount(): void {
// in Create<Resource>.php
}
Oh this is awesome! I can use $this->form->fill() in mount! Filament is amazing. I wish there was some intro documentation in regards to tightly integrated livewire is with Filament. This tiny epiphany just opened my eyes to what filament is capable of.
LeandroFerreira
LeandroFerreira7mo ago
You ask and you answer your question 😅

Did you find this page helpful?