use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use LivewireUI\Modal\ModalComponent;
class AddUserModal extends ModalComponent
{
// ...
public function addUser()
{
$this->validate();
$user = new User([
'name' => $this->name,
'contact_name' => $this->name,
'email' => $this->email,
'email_verified_at' => Carbon::now()->format('Y-m-d H:i:s'),
'is_admin' => $this->is_admin,
'password' => Hash::make(Str::random(8)), // temporary password
]);
$user->save();
$this->dispatch('refreshUsersList');
$this->closeModal();
$status = Password::sendResetLink(['email' => $this->email]);
if ($status === Password::RESET_LINK_SENT) {
$this->dispatch('notify', ['type' => 'success', 'message' => __('notifications.user_add_success')]);
} else {
$this->dispatch('notify', ['type' => 'error', 'message' => __('notifications.user_add_error')]);
}
}
// ...
}