1. Go to this page and download the library: Download simply-connect/laravel 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/ */
simply-connect / laravel example snippets
use SimplyConnect\Laravel\Facades\SimplyConnect;
$receipt = SimplyConnect::sms()
->to('+48500100200')
->text('Your order is ready for collection.')
->send();
$receipt = SimplyConnect::sms()
->to($customer->phone_number)
->text("Order {$order->number} has been shipped.")
->send();
$receipt->messageId;
$receipt->dispatchId;
$receipt->commandId;
$receipt->status; // MessageStatus::Queued
$receipt->idempotencyKey; // generated for this request
$receipt->correlationId; // useful when contacting support
use SimplyConnect\Laravel\Contracts\HasSmsNumber;
final class Customer implements HasSmsNumber
{
public function smsNumber(): string
{
return $this->phone_number;
}
}
SimplyConnect::sms()
->to($customer)
->text('Thank you for registering.')
->send();
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use SimplyConnect\Laravel\Notifications\SimplyConnectChannel;
use SimplyConnect\Laravel\Notifications\SmsMessage;
final class OrderShipped extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(private readonly string $orderNumber) {}
public function via(object $notifiable): array
{
return [SimplyConnectChannel::class];
}
public function toSimplyConnect(object $notifiable): SmsMessage
{
return SmsMessage::make("Order {$this->orderNumber} has been shipped.")
->via('notifications')
->withIdempotencyKey("order-{$this->orderNumber}-shipped");
}
}
public function routeNotificationForSimplyConnect(): string
{
return $this->phone_number;
}
use SimplyConnect\Laravel\Contracts\SimplyConnectClient;
final class SendVerificationCode
{
public function __construct(private SimplyConnectClient $simplyConnect) {}
public function handle(string $phone, string $code): void
{
$this->simplyConnect
->sms()
->to($phone)
->text("Your verification code is {$code}.")
->send();
}
}
use SimplyConnect\Laravel\Enums\MessageStatus;
$message = SimplyConnect::message($receipt->messageId);
if ($message->status === MessageStatus::Delivered) {
// The gateway reported successful delivery.
}
if ($message->hasFailed()) {
// FAILED, UNKNOWN or DEAD_LETTER needs application-specific handling.
}
foreach ($message->statusHistory as $event) {
logger()->info('SMS status evidence', [
'status' => $event->status->value,
'source' => $event->source,
'error_code' => $event->errorCode,
'occurred_at' => $event->occurredAt,
]);
}
SimplyConnect::sms()
->to($customer->phone_number)
->text('Your invoice is available.')
->withIdempotencyKey("invoice-{$invoice->id}-available")
->send();