phplaravelnusoaplaravel-controller

Use Custom Library in Controller of Laravel


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');

Solution

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

    use nusoap_client;