feat: add admin settings panel and dashboard configurations
This commit is contained in:
52
src/app/Http/Controllers/AdminController.php
Normal file
52
src/app/Http/Controllers/AdminController.php
Normal 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!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user