F
Filamentβ€’6mo 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
CGMOPβ€’6mo 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
LeandroFerreiraβ€’6mo ago
Yes, use default()
CGM
CGMOPβ€’6mo 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
LeandroFerreiraβ€’6mo ago
You ask and you answer your question πŸ˜…
Want results from more Discord servers?
Add your server