'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 === 'ecommerce') { $schema = [ ['key' => 'woo_store_url', 'name' => 'WooCommerce Store URL', 'type' => 'string', 'default' => 'https://example.com', 'description' => 'The base URL of your WooCommerce store (e.g. https://shop.stargas.co.za).'], ['key' => 'woo_consumer_key', 'name' => 'Consumer Key', 'type' => 'string', 'default' => '', 'description' => 'WooCommerce REST API Consumer Key (ck_...).'], ['key' => 'woo_consumer_secret', 'name' => 'Consumer Secret', 'type' => 'string', 'default' => '', 'description' => 'WooCommerce REST API Consumer Secret (cs_...).'], ['key' => 'fb_app_id', 'name' => 'Facebook App ID', 'type' => 'string', 'default' => '', 'description' => 'Your Facebook Application ID.'], ['key' => 'fb_app_secret', 'name' => 'Facebook App Secret', 'type' => 'string', 'default' => '', 'description' => 'Your Facebook Application Secret.'], ['key' => 'fb_access_token', 'name' => 'Facebook Access Token', 'type' => 'string', 'default' => '', 'description' => 'Long-lived Facebook Access Token for API calls.'], ['key' => 'fb_ad_account_id', 'name' => 'Facebook Ad Account ID', 'type' => 'string', 'default' => '', 'description' => 'Your Facebook Ad Account ID (e.g. act_123456789).'], ]; } 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!'); } }