middleware('admin'); } public function index() { $data = [ 'values' => [], ]; return view('admin.settings.index', $data); } public function store() { $data = Request::all(); if (isset($data['action'])) { if (isset($data['settings'])) { foreach ($data['settings'] as $key => $value) { $value['val'] = isset($value['val']) ? $value['val'] : false; Setting::setContentBySlug($key, $value['val'], $value['type']); } } // DHL-spezifische Behandlung if ($data['action'] === 'save_dhl') { $this->updateDhlConfigCache(); \Session()->flash('alert-save-dhl', 'DHL Konfiguration erfolgreich gespeichert!'); } else { \Session()->flash('alert-save', '1'); } } return redirect(route('admin_settings')); } /** * Get DHL configuration merged from database settings and .env values * Database settings override .env values */ public function getDhlConfig() { // Check if we're in test/sandbox mode $isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false); $baseUrl = $isTestMode ? config('dhl.sandbox_url') : config('dhl.base_url'); return [ // API Settings 'base_url' => $isTestMode ? $baseUrl : (Setting::getContentBySlug('dhl_base_url') ?: $baseUrl), 'api_key' => Setting::getContentBySlug('dhl_api_key') ?: config('dhl.api_key'), 'username' => Setting::getContentBySlug('dhl_username') ?: config('dhl.username'), 'password' => Setting::getContentBySlug('dhl_password') ?: config('dhl.password'), 'billing_number' => Setting::getContentBySlug('dhl_billing_number') ?: config('dhl.billing_number'), // Product Settings 'default_product' => Setting::getContentBySlug('dhl_product') ?: config('dhl.default_product'), 'label_format' => Setting::getContentBySlug('dhl_label_format') ?: config('dhl.label_format'), 'print_format' => Setting::getContentBySlug('dhl_print_format') ?: config('dhl.print_format'), 'retoure_print_format' => Setting::getContentBySlug('dhl_retoure_print_format') ?: config('dhl.retoure_print_format'), 'use_queue' => Setting::getContentBySlug('dhl_use_queue') ?: config('dhl.use_queue'), // Sender Address 'sender' => [ 'company' => Setting::getContentBySlug('dhl_sender_company') ?: config('dhl.sender.company'), 'name' => Setting::getContentBySlug('dhl_sender_name') ?: config('dhl.sender.name'), 'street' => Setting::getContentBySlug('dhl_sender_street') ?: config('dhl.sender.street'), 'houseNumber' => Setting::getContentBySlug('dhl_sender_house_number') ?: config('dhl.sender.houseNumber'), 'postalCode' => Setting::getContentBySlug('dhl_sender_postal_code') ?: config('dhl.sender.postalCode'), 'city' => Setting::getContentBySlug('dhl_sender_city') ?: config('dhl.sender.city'), 'country' => Setting::getContentBySlug('dhl_sender_country') ?: config('dhl.sender.country'), 'email' => Setting::getContentBySlug('dhl_sender_email') ?: config('dhl.sender.email'), 'phone' => Setting::getContentBySlug('dhl_sender_phone') ?: config('dhl.sender.phone'), ], // Account Numbers 'account_numbers' => [ 'V01PAK' => Setting::getContentBySlug('dhl_account_v01pak') ?: config('dhl.account_numbers.V01PAK'), 'V62WP' => Setting::getContentBySlug('dhl_account_v62wp') ?: config('dhl.account_numbers.V62WP'), 'V53PAK' => Setting::getContentBySlug('dhl_account_v53pak') ?: config('dhl.account_numbers.V53PAK'), 'V07PAK' => Setting::getContentBySlug('dhl_account_v07pak') ?: config('dhl.account_numbers.V07PAK'), 'default' => config('dhl.account_numbers.default'), ], // Dimensions 'dimensions' => [ 'V01PAK' => config('dhl.dimensions.V01PAK'), 'V62WP' => config('dhl.dimensions.V62WP'), 'V53PAK' => config('dhl.dimensions.V53PAK'), 'V07PAK' => config('dhl.dimensions.V07PAK'), 'default' => config('dhl.dimensions.default'), ], // Static config values (webhook, profile, legacy) 'profile' => config('dhl.profile'), 'webhook' => config('dhl.webhook'), 'legacy' => config('dhl.legacy'), ]; } /** * Update DHL configuration cache after saving settings */ private function updateDhlConfigCache() { // Clear config cache to force reload from database \Artisan::call('config:clear'); // Optional: Test DHL connection with new settings try { $dhlManager = app('Acme\Dhl\DhlManager'); // You could add a connection test here if needed \Log::info('DHL configuration updated successfully'); } catch (\Exception $e) { \Log::error('DHL configuration update failed: ' . $e->getMessage()); } } }