password) { $user->passwordHistories()->create([ 'password_hash' => $user->password, 'created_at' => now(), ]); } $user->forceFill([ 'password' => Hash::make($newPassword), 'password_changed_at' => now(), ])->save(); $this->trimHistory($user); }); } private function trimHistory(User $user): void { $limit = PasswordPolicy::historyLimit(); $ids = $user->passwordHistories() ->orderByDesc('created_at') ->skip($limit) ->take(PHP_INT_MAX) ->pluck('id'); if ($ids->isNotEmpty()) { $user->passwordHistories()->whereIn('id', $ids)->delete(); } } }