get(); $title = 'Cấu hình hệ thống'; return view('backend.parameter.index')->with('data', $data)->with('title', $title); } public function update (Request $request) { // Validate image file types before processing to prevent unrestricted file upload (OWASP A05) $request->validate([ 'logo_image' => 'nullable|mimes:jpg,png,jpeg,webp,jfif|max:2048', 'banner_image' => 'nullable|mimes:jpg,png,jpeg,webp,jfif|max:2048', ], [ 'logo_image.mimes' => 'Logo chỉ chấp nhận định dạng jpg, png, jpeg, webp', 'banner_image.mimes' => 'Banner chỉ chấp nhận định dạng jpg, png, jpeg, webp', ]); foreach ($request->except('_token') as $key => $value) { $object = Parameter::where('parameter_key', $key)->first(); if ($object != '') { if ($key == 'logo_image' || $key == 'banner_image') { $this->updateParameterImage($key, $request, $object); } else { $object->parameter_value = $value; $object->save(); } } } return redirect()->back()->with('success', 'Cập nhật thành công'); } public function updateParameterImage ($input_name, $request, $object) { if($request->file($input_name)) { $imageName = $input_name . '.' . $request->file($input_name)->extension(); $counter = 0; // Vòng lặp kiểm tra tên file và thêm số nếu trùng while (File::exists(public_path('images') . '/parameter/' . $imageName)) { $counter++; $imageName = $input_name . '(' . $counter . ').' . $request->file($input_name)->extension(); } $request->file($input_name)->move(public_path('images/parameter'), $imageName); $previous_img_path = $object->parameter_value; $object->parameter_value = 'parameter/' . $imageName; $object->save(); if($previous_img_path != '' && File::exists(public_path('images') . '/' . $previous_img_path)) { File::delete(public_path('images') . '/' . $previous_img_path); } } } }