Laravel
WhatsApp API for Laravel
Laravel support ships inside the same Composer package as the PHP client. Install it and Laravel auto-discovery registers a service provider that builds the client from your config, so you inject it like any other service and send WhatsApp messages from controllers, jobs or commands.
One package, not two
There is no separate Laravel SDK. wasaas/wasaas-php declares a Laravel service provider and facade alias in its extra.laravel block, which is what makes auto-discovery work. Everything on the PHP page applies here too; this page covers only the Laravel wiring.
Install
composer require wasaas/wasaas-phpPublished on Packagist as wasaas/wasaas-php (version 1.0.0).
Requires PHP ^8.1 with ext-json. Laravel discovers Wasaas\Laravel\WasaasServiceProvider automatically — nothing to add to config/app.php.
Configure
Add your credentials to .env:
WASAAS_API_KEY=wsa_your_api_key
WASAAS_BASE_URL=https://wasaas.orgWASAAS_BASE_URL is optional and defaults to https://wasaas.org. Publish the config file if you want it in your repository:
php artisan vendor:publish --tag=wasaas-configThat writes config/wasaas.php, which reads both values from the environment.
Resolve the client
The provider registers Wasaas\WasaasClient as a singleton built from your config, aliased in the container as wasaas. Constructor injection is the idiomatic way in:
<?php
namespace App\Http\Controllers;
use Wasaas\WasaasClient;
class OrderController extends Controller
{
public function __construct(private readonly WasaasClient $wasaas) {}
public function shipped(Order $order)
{
$this->wasaas->messages->sendText(
sessionId: config('services.wasaas.session'),
to: $order->customer->whatsapp,
message: "Order #{$order->id} has shipped.",
);
return back();
}
}Outside a constructor, resolve it from the container:
app(\Wasaas\WasaasClient::class)->messages->sendText($sessionId, $to, $message);
// The container alias resolves to the same singleton:
app('wasaas')->messages->sendText($sessionId, $to, $message);Call through the resources, not the facade shortcut
The package registers a Wasaas facade alias, and its docblock advertises static shortcuts such as Wasaas::sendText(...). Those shortcuts do not work in version 1.0.0: the facade resolves to WasaasClient, which exposes messages, sessions and numbers as properties and defines no sendText method, so a static call raises BadMethodCallException.
Use injection or app(...) as shown above and go through ->messages->sendText(...).
Queue it
Sending is a synchronous HTTP call, so put it in a job rather than a request cycle when the user is waiting. Failed sends throw WasaasApiException, which Laravel's retry handling treats like any other exception.
<?php
namespace App\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Wasaas\Exceptions\WasaasApiException;
use Wasaas\WasaasClient;
class SendWhatsAppMessage implements ShouldQueue
{
public int $tries = 3;
public function __construct(
private readonly string $to,
private readonly string $message,
) {}
public function handle(WasaasClient $wasaas): void
{
try {
$wasaas->messages->sendText(
sessionId: config('services.wasaas.session'),
to: $this->to,
message: $this->message,
);
} catch (WasaasApiException $e) {
// 429 means the monthly quota is spent — do not burn retries on it.
if ($e->getStatusCode() === 429) {
$this->fail($e);
return;
}
throw $e;
}
}
}Where to go next
- WhatsApp API for PHP — the full client surface: images, documents, sessions, number checks
- WhatsApp REST API documentation — endpoints, request fields and error codes
- WhatsApp API pricing — message, session and API-call allowances per plan
- WhatsApp bulk messaging API — for campaigns, where one call fans out to many recipients