lk.zachem.info/app/Models/ForcedPassword.php
2025-06-16 15:09:46 +08:00

22 lines
515 B
PHP

<?php
namespace App\Models;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use App\Notifications\UserRegistered;
trait ForcedPassword
{
public function setForcedPassword($sendToEmail = true)
{
$newPassword = Str::password(8);
$this->password = Hash::make($newPassword);
$this->save();
if ($sendToEmail)
{
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
}
return $newPassword;
}
}