feat: add admin settings panel and dashboard configurations

This commit is contained in:
theRAD
2026-03-06 04:58:29 +02:00
parent d705160b55
commit d404054887
8 changed files with 336 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Setting;
class AdminController extends Controller
{
public function index()
{
return view('admin.index');
}
public function dashboardSettings($dashboard)
{
// Define available settings per dashboard here for simplicity
$schema = [];
if ($dashboard === 'procurement') {
$schema = [
['key' => 'target_margin', 'name' => 'Target Margin (%)', 'type' => 'integer', 'default' => 20, 'description' => 'Target gross margin percentage for alerts.'],
['key' => 'low_stock_threshold', 'name' => 'Low Stock Warning', 'type' => 'integer', 'default' => 50, 'description' => 'Quantity at which a product is considered low stock.'],
['key' => 'default_date_range', 'name' => 'Default Date Filter', 'type' => 'string', 'default' => 'YTD', 'description' => 'Default date range on load (e.g. YTD, All).'],
];
} else if ($dashboard === 'sales') {
$schema = [
['key' => 'monthly_target', 'name' => 'Monthly Sales Target', 'type' => 'integer', 'default' => 100000, 'description' => 'Overall monthly sales target.'],
];
} else {
abort(404);
}
// Fetch current settings from DB
$settings = Setting::where('dashboard', $dashboard)->get()->keyBy('key');
return view('admin.settings', compact('dashboard', 'schema', 'settings'));
}
public function updateSettings(Request $request, $dashboard)
{
$settingsData = $request->except('_token');
foreach ($settingsData as $key => $value) {
Setting::updateOrCreate(
['dashboard' => $dashboard, 'key' => $key],
['value' => $value]
);
}
return redirect()->back()->with('success', ucfirst($dashboard) . ' settings saved successfully!');
}
}