39 lines
870 B
PHP
39 lines
870 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class UpdatePasswordRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'current_password' => ['required'],
|
|
'new_password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
];
|
|
}
|
|
|
|
public function withValidator($validator)
|
|
{
|
|
$validator->after(function ($validator) {
|
|
if (!Hash::check($this->current_password, $this->user()->password)) {
|
|
$validator->errors()->add('current_password', 'رمز عبور فعلی صحیح نیست.');
|
|
}
|
|
});
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
}
|