0

I wanted to use nusoap_client class so decided to add nusoap library to my laravel project. Like other libraries, i used github readme page to get it done.

composer require econea/nusoap:^0.9.6

This library was added to ../vendor/econea/nusoap/src/nusoap.php. Then i wanted to use it in my controller but i tried many ways to use it like below :

use SoapClient;
use vendor\econea\nusoap\src\nusoap.php;
use nusoap.php;
use nusoap;

I even tried to load library in autoload in composer.json file without any luck. laravel kept repeating same error.

Class 'App\Http\Controllers\nusoap_client' not found

I appreciate any help given that suggests a way to use nusoap_client in my code or the correct way to use the library in my laravel project. thanks.

my code:

$client = new nusoap_client('example.com/api/v1', 'wsdl');
Mehran Zamani
  • 831
  • 9
  • 31

2 Answers2

2

The proper syntax at the top of your controller should be:

use nusoap_client;
Adam Rodriguez
  • 1,850
  • 1
  • 12
  • 15
1

This is happening because this class does not contain a valid namespace.

So, you need to import this PHP file into your script using the require function.

To solve this in laravel, just import your file using composer like:

"autoload": {
    "files": ["path/to/vendor/script"]
}

With autoloaded file, you can instantiate the class in any script class of your project.

But, I don't think that's a good way to work with modern PHP. I know another library that works with SOAP: https://github.com/artisaninweb/laravel-soap

It's a wrapper for SoapClient http://php.net/manual/pt_BR/class.soapclient.php, a PHP core class that provides a soap client.

Hope my contribution can be useful and my english understandable.

common sense
  • 3,775
  • 6
  • 22
  • 31