select box
This commit is contained in:
@@ -146,6 +146,31 @@ class AdminController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete card allocation history record.
|
||||
*/
|
||||
public function destroyAddCard(Request $request, int $id)
|
||||
{
|
||||
try {
|
||||
$this->adminService->destroyAddCard($id);
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Xóa lịch sử cấp phát thẻ thành công.',
|
||||
]);
|
||||
}
|
||||
return redirect()->back()->with('success', 'Xóa lịch sử cấp phát thẻ thành công.');
|
||||
} catch (\Exception $e) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
], 422);
|
||||
}
|
||||
return redirect()->back()->withErrors(['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cards for active users.
|
||||
*/
|
||||
|
||||
@@ -116,8 +116,8 @@ class UserController extends Controller
|
||||
|
||||
$this->userService->updateProfile(
|
||||
$user,
|
||||
$request->file('avatar'),
|
||||
$request->filled('new_password') ? $request->input('new_password') : null
|
||||
$request->validated(),
|
||||
$request->file('avatar')
|
||||
);
|
||||
|
||||
return redirect()->route('user.edit')->with('success', 'Cập nhật hồ sơ thành công');
|
||||
|
||||
@@ -29,6 +29,8 @@ class UpdateUserRequest extends FormRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$msnv = $this->route('msnv');
|
||||
|
||||
return [
|
||||
'card' => 'nullable|integer|min:0',
|
||||
'num_card' => 'nullable|integer|min:1',
|
||||
@@ -36,6 +38,12 @@ class UpdateUserRequest extends FormRequest
|
||||
'status' => 'nullable|in:' . config('constants.STATUS_INACTIVE') . ',' . config('constants.STATUS_ACTIVE'),
|
||||
'flag_send' => 'nullable|in:0,1',
|
||||
'first_login' => 'nullable|in:' . config('constants.FIRST_LOGIN_FALSE') . ',' . config('constants.FIRST_LOGIN_TRUE'),
|
||||
|
||||
// Editable basic info
|
||||
'name' => 'sometimes|required|string|max:255',
|
||||
'mail' => 'sometimes|required|email|unique:user,mail,' . $msnv . ',msnv',
|
||||
'departments' => 'sometimes|required|string|in:' . implode(',', config('constants.DEPARTMENTS')),
|
||||
'avatar' => 'nullable|image|max:2048',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,35 @@ class UpdateProfileRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'avatar' => 'nullable|image|max:2048', // 2MB max
|
||||
'new_password' => 'nullable|min:6|confirmed',
|
||||
'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.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user