| Current Path : /home/users/unlimited/www/foodbank.codeskitter.site/app/Http/Requests/ |
| Current File : /home/users/unlimited/www/foodbank.codeskitter.site/app/Http/Requests/ChangePasswordRequest.php |
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
class ChangePasswordRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'old_password' => ['required', 'string', 'min:6'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
'password_confirmation' => ['required', 'string', 'min:6',],
];
}
public function withValidator($validator)
{
$validator->after(function ($validator) {
if (!$this->checkOldPassword()) {
$validator->errors()->add('old_password', 'The old password does not match.');
}
});
}
public function checkOldPassword()
{
$old_password = request('old_password');
return Hash::check($old_password, auth()->user()->password);
}
}