Laravel 8项目调用SOAP API提示‘Class SoapClient not found’错误求助(已启用XAMPP SOAP扩展)
Let's walk through the most common fixes for this issue, since you already tried enabling the SOAP extension in XAMPP but it's still not working:
1. Double-check you edited the correct php.ini file
XAMPP has two separate php.ini files—one for the Apache web server, and one for the CLI (command line interface). If you edited the wrong one, the SOAP extension won't load for your Laravel app:
- For Apache (when accessing your app via browser or
artisan serve), the file is usually atC:\xampp\apache\bin\php.ini - For CLI (if you're running queue workers, migrations, etc.), it's at
C:\xampp\php\php.ini
To confirm which one your app is using:
- Create a temporary
phpinfo.phpfile in your Laravel public folder with this code:<?php phpinfo(); ?> - Access it via your browser (e.g.,
http://localhost/API/public/phpinfo.php), then search for "soap". If you don't see sections for "Soap Client" and "Soap Server", you edited the wrongphp.ini.
2. Properly enable the SOAP extension
Once you have the correct php.ini file:
- Find the line that looks like
;extension=soap(or;extension=php_soap.dllfor Windows) - Remove the leading semicolon (
;) to uncomment the line - Save the file, then restart XAMPP's Apache service (this is critical—changes won't take effect until you restart!)
3. Verify CLI PHP has SOAP enabled (if needed)
If you're running Laravel commands via CLI (like php artisan serve or queue jobs), check if SOAP is enabled there too:
- Open Command Prompt (CMD) and run:
php -m - Look for "soap" in the list of modules. If it's missing, edit the
C:\xampp\php\php.inifile as described above, then close and reopen your CMD window (restarting the shell is needed for changes to apply).
4. Double-check your code
Your current code uses \SoapClient (global namespace), which is correct—just make sure you didn't misspell it (it's case-sensitive: SoapClient, not soapclient or Soapclient).
Final Troubleshooting Tip
If none of the above works, try restarting your entire computer (sometimes XAMPP holds onto old PHP processes). Also, confirm that your XAMPP PHP version is compatible with the SOAP extension (most modern XAMPP versions include it by default, so this is rarely an issue).
内容的提问来源于stack exchange,提问作者Hoda Kh

