PHP code example of aghfatehi / laravel-msegat
1. Go to this page and download the library: Download aghfatehi/laravel-msegat 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/ */
aghfatehi / laravel-msegat example snippets
use Aghfatehi\Msegat\Facades\Msegat;
// Single recipient
$response = Msegat::sms()
->to('966512345678')
->message('Hello World')
->send();
// Multiple recipients
$response = Msegat::sms()
->to(['966512345678', '966598765432'])
->message('Bulk message')
->send();
// Custom sender
$response = Msegat::sms()
->sender('CustomAD')
->to('966512345678')
->message('Custom sender test')
->send();
// Scheduled message
$response = Msegat::sms()
->to('966512345678')
->message('Scheduled message')
->at('2026-12-01 10:00:00')
->send();
// Get bulk ID
$response = Msegat::sms()
->to(['966512345678', '966598765432'])
->message('Get bulk ID')
->options(['reqBulkId' => true])
->send();
$bulkId = $response->bulkId;
$response = Msegat::sms()
->to(['966512345678', '966598765432'])
->message('Hello {name}, your order {order} is ready')
->sendPersonalized([
['name' => 'Ahmed', 'order' => '1001'],
['name' => 'Mohammed', 'order' => '1002'],
]);
// Send OTP
$otpResponse = Msegat::otp()
->to('966512345678')
->sendOtp();
$otpId = $otpResponse->otpId;
// Verify OTP
$verification = Msegat::otp()
->to('966512345678')
->verifyOtp('123456');
if ($verification->successful) {
// OTP verified
}
$response = Msegat::whatsapp()
->to('966512345678')
->message('Hello from WhatsApp!')
->send();
$messageId = $response->messageId;
$response = Msegat::whatsapp()
->to('966512345678')
->template('welcome')
->variables(['John', 'Support'])
->send();
if ($response->successful) {
echo "Sent: {$response->messageId}";
}
$balance = Msegat::getBalance();
$credits = $balance->balance; // float
$cost = Msegat::sms()
->to(['966512345678', '966598765432'])
->message('Test message')
->calculateCost();
// Returns float
// List senders
$senders = Msegat::getSenders();
// Add sender
// (available via direct API call - endpoint: addSender.php)
$messages = Msegat::forBulkId('BULK123')
->getMessages();
$messages = Msegat::forBulkId('BULK123')
->page(2)
->limit(10)
->getMessages();
Msegat::sms()
->to('966512345678')
->sendTestMessage();
// Dispatch to default queue
Msegat::sms()
->to('966512345678')
->message('Queued message')
->queue();
// Custom queue connection
Msegat::sms()
->to('966512345678')
->message('Queued message')
->queue('redis', 'high');
protected $listen = [
\Aghfatehi\Msegat\Events\MessageSent::class => [
\App\Listeners\LogMsegatMessage::class,
],
];
namespace App\Notifications;
use Illuminate\Notifications\Notification;
class WelcomeSms extends Notification
{
public function via($notifiable): array
{
return ['msegat'];
}
public function toMsegat($notifiable): string
{
return "Welcome {$notifiable->name} to our platform!";
}
}
public function routeNotificationForMsegat(): string
{
return $this->phone;
}
bash
php artisan vendor:publish --provider="Aghfatehi\Msegat\MsegatServiceProvider" --tag=msegat-config
bash
php artisan migrate --path=/vendor/aghfatehi/laravel-msegat/database/migrations
bash
php artisan vendor:publish --provider="Aghfatehi\Msegat\MsegatServiceProvider" --tag=msegat-migrations
php artisan migrate
bash
# Check account balance
php artisan msegat:balance
# List registered senders
php artisan msegat:senders