Files
thankcard-system/app/Http/Requests/User/UpdateProfileRequest.php
2026-07-13 16:28:44 +07:00

55 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests\User;
use Illuminate\Foundation\Http\FormRequest;
class UpdateProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'avatar' => 'nullable|image|max:2048', // 2MB max
'current_password' => [
'nullable',
'required_with:new_password',
function ($attribute, $value, $fail) {
if ($value && md5($value) !== auth()->user()->pass) {
$fail('Mật khẩu hiện tại không chính xác.');
}
},
],
'new_password' => 'nullable|min:6|confirmed|different:current_password',
];
}
/**
* Get the error messages for the defined validation rules.
*/
public function messages(): array
{
return [
'name.required' => 'Họ và tên không được để trống.',
'name.string' => 'Họ và tên phải là chuỗi ký tự.',
'name.max' => 'Họ và tên không được vượt quá 255 ký tự.',
'avatar.image' => 'Ảnh đại diện phải là tệp ảnh.',
'avatar.max' => 'Ảnh đại diện không được vượt quá 2MB.',
'new_password.min' => 'Mật khẩu mới phải có ít nhất 6 ký tự.',
'new_password.confirmed' => 'Mật khẩu xác nhận không trùng khớp.',
'new_password.different' => 'Mật khẩu mới phải khác mật khẩu hiện tại.',
];
}
}