12

I want to use php's built in SoapClient class in laravel 5

I tried using it directly is shows error saying

Class 'App\Http\Controllers\SoapClient' not found.

I tried adding SoapClient in aliases array in config/app.php like this

'SoapClient' => SoapClient::class

Still not working

what should I do?

Thanks in Advance...

Akshay Khale
  • 8,151
  • 8
  • 50
  • 58

3 Answers3

40

The class needs to be imported, so either do that at the top:

use SoapClient;

or reference it directly later:

$client = new \SoapClient($wsdl, $options);

Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
2

I faced with same problem.

I activated Soap extension after I use php artisan serve command and although I restarted my apache server I received same error..

After too many tries I stop artisan and restart it again and that was the solution for me.

Serdar D.
  • 3,055
  • 1
  • 30
  • 23
0

You need to have libxml and soap extensions installed for it to load the SoapClient class.

So check php -i | grep limxml and php -i | grep soapto see if they are installed.

For php 7.2 this would be needed to apt install and restart php/server.

apt-get install libxml php7.2-soap

Then check your php ini again. ubuntu ini path for the conf

/etc/php/7.2/cli/conf.d/20-soap.ini

extension=soap.so

After that you should be able to run new object command.

tristanbailey
  • 4,427
  • 1
  • 26
  • 30