nusoap icon indicating copy to clipboard operation
nusoap copied to clipboard

Integration with laravel

Open manu2319 opened this issue 8 years ago • 3 comments

In the controller use this:

$server->framework = 'laravel'; $server->route_class = "App\Http\Controllers"; $server->register("class.hello", array('nombre' => 'xsd:string'), array('return' => 'xsd:string') );

manu2319 avatar Nov 29 '17 07:11 manu2319

Thanks for PR. Well, it's big change to nusoap, could you please add some testcase? I wouldn't like to break all systems. :-)

f3l1x avatar Nov 29 '17 07:11 f3l1x

Sorry my english is bad.

first install nusoap:

composer require econea/nusoap

Hello, this is my Controller in Laravel #App\Http\Controllers

I have added two properties, which are:

this property is to add the used framework

$server->framework = 'laravel';

this property is to add the driver path

$server->route_class = "App\Http\Controllers";

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use soap_server;
use soapval;

class soapOntas extends Controller
{
    //
    
    public function index(){
        $URL       = "http://localhost/soap";
        $namespace = $URL . '?wsdl';
        //using soap_server to create server object
        $server    = new soap_server();
        $server->configureWSDL('OntasSave', $namespace, $namespace);
        
        
        
        //register a function that works on server

        $server->framework = 'laravel';
        $server->route_class = "App\Http\Controllers";

        $server->register("soapOntas.hello",
            array('name' => 'xsd:string'),
            array('return' => 'xsd:string')
        ); 
        // create the function
        
        // create HTTP listener
        if ( !isset( $HTTP_RAW_POST_DATA ) ) {
            $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
       }
        $server->service($HTTP_RAW_POST_DATA);
        exit();
    }
    public function hello($name){
        return new soapval('return', 'xsd:string', $name);
    }
   
    

}

in my route:

#Routes\

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::any('/soap', 'soapOntas@index');


in my Middleware:

#App\Http\Middleware

edit the file VerifyCsrfToken

add the route

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        "soap"
    ];
}

regards,

manu2319 avatar Nov 30 '17 14:11 manu2319

Hello, I am trying to install nusoap server with laravel 7 but the next properties I think they don't work anymore

$server->framework = 'laravel'; $server->route_class = "App\Http\Controllers";

will you happen to have an example of its implementation in a laravel controller?

zerobyt avatar May 29 '20 01:05 zerobyt