Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

John316's avatar

Laravel & NuSOAP problem

Hi,

I'm having an interesting problem regarding Laravel 5.2 and NuSOAP.

When defining a NuSOAP service in an inline route closure function, the NuSOAP web service works fine without any problems:

routes.php:

Route::any('api', function() {

    require_once ('nusoap.php');
    $server = new \nusoap_server();

    $server->configureWSDL('TestService', false, url('api'));

    $server->register('test',
        array('input' => 'xsd:string'),
        array('output' => 'xsd:string'),
        'xsd:demo');

    function test($input){
        return $input;
    }

    $rawPostData = file_get_contents("php://input");
    return \Response::make($server->service($rawPostData), 200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));

  });

client

require_once('nusoap.php');

$client = new nusoap_client('http://.../api?wsdl', true);

$result = $client->call("test", "just a string");

print_r($result); exit();

just a string

However, when moving this code to a dedicated controller:

routes.php:

Route::any('api', 'SoapController@server');

SoapController.php:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SoapController extends Controller {

    public function __construct() {
    }

    public function server() {
       // NuSOAP service code here 
    }

}

...the following error message is returned:

"method 'test' ('test') not defined in service('' '')

What could cause this behaviour? Could it be a middleware that's blocking access when the code is in a controller?

Do you have any ideas?

Thanks!

0 likes
1 reply
ginzunza's avatar

Yep, your problem is related with "test" function. If you want to use this function in that way, then you could fix it by defining your function test in helpers, because it will be added by default. If you try to define a function inside another function it won't work. Another alternative is creating a class with a test method and adding it in your controller with "use App\ClassName".

Please or to participate in this conversation.