Mutate Data before Create (calculated column)

Hello. I need to calculate a column with series & id. The fields are Id, Series, NumExp and I need numExp to be equal to SERIES-ID If series is ABC and id is 20, I need numExp to be ABC20 I have tried this mutateFormDataBeforeCreate but it is not working.
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['numExp'] = $data['serie'] . '-' . $data['id'];
return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['numExp'] = $data['serie'] . '-' . $data['id'];
return $data;
}
Is there a boot method in the Model or something, please? Tks.
Solution:
Finally I have created an Observer. Thank you....
Jump to solution
5 Replies
Albert Lens
Albert LensOP10mo ago
I already tried but I get an error because Id field is not available for virtualAs.
lazydog
lazydog10mo ago
Okay, you need this one protected function handleRecordCreation(array $data): Model just call the parent method then update the field you want
Albert Lens
Albert LensOP10mo ago
Tks. And where (in which file) do I have to put that function handleRecordCreation() ??
Solution
Albert Lens
Albert Lens10mo ago
Finally I have created an Observer. Thank you.
Want results from more Discord servers?
Add your server