simedkom/app/Rules/MatchCurrentPasswordRule.php
2025-10-13 08:35:36 +07:00

26 lines
663 B
PHP

<?php
namespace App\Rules;
use App\Models\User;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class MatchCurrentPasswordRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$user = User::find(Auth::id());
if (! Hash::check($value, $user->password)) {
$fail('Kata sandi saat ini tidak sesuai.');
}
}
}