PHP code example of ashararsi / laravel-whatsapp-cloud
1. Go to this page and download the library: Download ashararsi/laravel-whatsapp-cloud library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ashararsi / laravel-whatsapp-cloud example snippets
use Vendor\LaravelWhatsAppCloud\Facades\WhatsApp;
// Send a text message (uses default account)
WhatsApp::send('923001234567', 'Hello World');
// Target a specific account
WhatsApp::account(1)->sendText('923001234567', 'Hello');
WhatsApp::using('marketing')->send('923001234567', 'Sale Started');
// Queue for background delivery
WhatsApp::queue()->send('923001234567', 'Queued message');
// Send a template with variables
WhatsApp::template('923001234567', 'order_confirmed', ['Ali', '#12345']);
use Vendor\LaravelWhatsAppCloud\Contracts\TenantResolverInterface;
class TenantResolver implements TenantResolverInterface
{
public function resolve(): ?int
{
return auth()->user()?->tenant_id;
}
}
use Vendor\LaravelWhatsAppCloud\Notifications\WhatsAppChannel;
public function via($notifiable): array
{
return [WhatsAppChannel::class];
}
public function toWhatsApp($notifiable): array
{
return [
'using' => 'twilio-support', // or account ID
'text' => 'Your order shipped!',
'queue' => true,
];
}
use Vendor\LaravelWhatsAppCloud\Events\MessageReceived;
Event::listen(MessageReceived::class, function (MessageReceived $event) {
// Handle incoming message (Meta or Twilio)
});