user()->role === 'admin', 403); abort_unless(in_array($provider, ['parcel2go', 'bambuddy', 'dryer'], true), 404); $rules = match ($provider) { 'parcel2go' => [ 'client_id' => ['nullable', 'string', 'max:255'], 'client_secret' => ['nullable', 'string', 'max:255'], 'auth_url' => ['nullable', 'url:https', 'max:2048'], 'base_url' => ['nullable', 'url:https', 'max:2048'], 'scope' => ['nullable', 'string', 'in:public-api,public-api my-profile,public-api payment,public-api payment my-profile'], ], default => [ 'url' => ['nullable', 'url:https', 'max:2048'], 'api_key' => ['nullable', 'string', 'max:512'], ], }; $submitted = array_filter($request->validate($rules), fn (?string $value): bool => filled($value)); $effective = $settings->for($provider); if ($submitted === [] && ! collect($effective)->contains(fn ($value): bool => filled($value))) { return redirect()->route('settings.index')->with('status', 'No integration settings changed.'); } $record = IntegrationSetting::find($provider) ?? new IntegrationSetting(['provider' => $provider]); $record->settings = array_replace($effective, $submitted); $record->save(); return redirect()->route('settings.index')->with('status', ucfirst($provider).' settings saved.'); } }