first commit

This commit is contained in:
2026-03-26 09:28:14 +07:00
commit fa46a144d8
20180 changed files with 2692766 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Parameter;
use Auth;
use Session;
use Illuminate\Support\Facades\File;
class ParameterController extends Controller
{
public function index() {
$data = Parameter::orderBy('parameter_order', 'asc')->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) {
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);
}
}
}
}