lk.zachem.info/app/Models/ForcedPassword.php
2024-12-16 00:51:01 +08:00

19 lines
454 B
PHP

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