Create Action on relation manager, how to generate a password ?

Hello, do you know in a relation manager how can I define a password and send a mail after the creation.. ? Since it's a static method and I can't store the password as a property of my object.
Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data) {
$data['type'] = UserTypeEnum::PARTNER;
$data['password'] = ($this->password = Hash::make(Str::random(15))); // don't work on a static method
return $data;
})->after(fn () => Mail::to($this->record)->send(
new UserCredentials($this->record, $this->password)
)),
Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data) {
$data['type'] = UserTypeEnum::PARTNER;
$data['password'] = ($this->password = Hash::make(Str::random(15))); // don't work on a static method
return $data;
})->after(fn () => Mail::to($this->record)->send(
new UserCredentials($this->record, $this->password)
)),
7 Replies
wyChoong
wyChoong2y ago
Can you access $record or $data in after closure? after(fn($record) =>…)
Dan Harrin
Dan Harrin2y ago
probably $data there
SUNSHINE
SUNSHINEOP2y ago
What you mean by $data there ?
Dan Harrin
Dan Harrin2y ago
->after(fn ($data) =>
SUNSHINE
SUNSHINEOP2y ago
@Dan Harrin But data contain the hashed password, not the real password
Hash::make($this->password = Str::random(15));
Hash::make($this->password = Str::random(15));
I'm trying to get the random string before the hash generation.
wyChoong
wyChoong2y ago
Can you try assigning to a variable $this->tmp Or do the update of record password in after But sending password in email might not be the best idea
Dan Harrin
Dan Harrin2y ago
yes sending a password in an email is a huge security risk
Want results from more Discord servers?
Add your server