sourcetoad/soapy is a Laravel package for a soap client built for laravel..
It currently has 12 GitHub stars and 99.918 downloads on Packagist (latest version v3.1.0).
Install it with composer require sourcetoad/soapy.
Discover more Laravel packages by sourcetoad
or browse all Laravel packages to compare alternatives.
Last updated
SOAP is old, but still used. Soapy is modern, but feature limited to fit our use cases.
Heavily inspired by artisaninweb/laravel-soap.
This package is currently supporting Laravel 11.x and 12.x.
composer require sourcetoad/soapy
This package will use Laravel Auto Discovery to automatically register the Service Provider.
Creating a client and making a request with class maps.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) {
return $curtain
->setWsdl('https://example.org?wsdl')
->setTrace(true)
->setOptions([
'encoding' => 'UTF-8'
])
->setClassMap([
'Foo' => Foo::class,
'FooResponse' => FooResponse::class
])
->setCache(WSDL_CACHE_MEMORY)
->setLocation('https://example.org');
});
Presuming you had XML for the expected request like this.
<Foo>
<bar>Connor</bar>
<baz>true</baz>
</Foo>
You could produce a matching class to resemble that data.
<?php
class Foo {
protected $bar;
protected $baz;
public function __construct(string $bar, bool $baz) {
$this->bar = $bar;
$this->baz = $baz;
}
}
You could then call a fictitious method name "fizz" on the SOAP Class like.
$this->client->call('fizz', new Foo("Connor", true));
This shows the benefit of never messing with XML directly.
Likewise for the response. Imagine you got back this.
<FooResponse>
<status>Success.</status>
</FooResponse>
This can also be mapped with the following class.
<?php
class FooResponse {
protected $status;
}
So now you can do:
echo $this->client->call('fizz', new Foo("Connor", true))->status;
// Success.
This example shows bare minimum WSDL location and no class maps.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) {
return $curtain
->setWsdl('https://example.org?wsdl')
});
Presuming you had XML for the expected request like this.
<Foo>
<bar>Connor</bar>
<baz>true</baz>
</Foo>
You could then call a fictitious method name "fizz" on the SOAP Class like.
$this->client->call('fizz', [
'bar' => 'Connor',
'baz' => true
});
This is more error prone due to human error with keys, but less work.
Sometimes you may have a SOAP Integration that just isn't fun. It may use something that our default SoapyClient cannot handle. This is okay, because patching a generic SOAP Client for all the strangeness that can happen is not feasible.
Start with a new class, that extends our SoapyBaseClient.
<?php
class CustomClass extends \Sourcetoad\Soapy\SoapyBaseClient {
//
}
From that class. You can overload any of the functions it provides.
Then pass the class name (fully qualified) to the Curtain during generation.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) {
return $curtain
->setWsdl('https://example.org?wsdl')
}, CustomClass::class);