Send email after register user
Hi guys, I have a simple user registration form to input the name and email, and I need that when the user registers, an email is automatically sent to reset the password.
I have this form. I'm using afterCreate hook with this:
protected function afterCreate(): void
{
$user = $this->record;
$token = app('auth.password.broker')->createToken($user);
$notification = new ResetPassword($token);
$notification->url = Filament::getResetPasswordUrl($token, $user);
$user->notify($notification);
}
But I receive Field 'password' doesn't have a default value. Have I save a random value before to create user?17 Replies
When creating user password cannot be null which seems to be in your case
I know, but for this case I need to set ->nullable() on migration or existe another case use?
Set a random password when creating a user
I did:
TextInput::make('password')->required()->password()->default(Hash::make(Str::random(13)))->hidden(),
But I receive the same errorHidden is the problem
Can this field be sent even if it has the 'hidden' value?
Also for random password https://laravel.com/docs/10.x/strings#method-str-password
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
And stop replying like that to every message
Hidden field can't be saved to db and it's a security concern
Ah ok thank you sorry
You need to mutatedatabeforesave
I could do this beforeCreate hooks?
Use your ide to find correct method
thank you for your help!
You can also use Eloquent events by hooking into the
creating
event and setting a random password if none is provided.
It's possible to send Filament::getResetPasswordUrl($token, $user); to an specific panel? I'm creating new users from admin panel but I want to send an email to users with client panel link
I've not used it but digging into the code got me the following snippet. Check if it meets your needs or was it a dumb call.
You can pass the same parameters to this method. The definition is similar to
Filament::getResetPasswordUrl
.
It's exactly what I was looking for! Thank you so much!!