PHP code example of mahdi-hejazi / laravel-ghasedak-sms
1. Go to this page and download the library: Download mahdi-hejazi/laravel-ghasedak-sms 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/ */
mahdi-hejazi / laravel-ghasedak-sms example snippets
// Track your OTP with custom reference ID
$clientRefId = 'USER_123_VERIFY_' . time();
$response = GhasedakSms::sendOtpVerificationCode('09123456789', '1234', $clientRefId);
// Later, you can use this reference ID to check status
// Old way with positional parameters
GhasedakSms::sendTemplate('09123456789', 'phoneVerifyCode', ['1234']);
// New way with named parameters
GhasedakSms::sendOtp('09123456789', 'phoneVerifyCode', ['Code' => '1234']);
// Or using the convenience method
GhasedakSms::sendOtpVerificationCode('09123456789', '1234');
namespace App\Notifications;
use MahdiHejazi\LaravelGhasedakSms\Notifications\SendSmsNotification;
class CustomSmsNotification extends SendSmsNotification
{
// Add your custom factory methods
public static function appointmentReminder($phone, $doctorName, $date, $time)
{
return new self('appointmentReminder', $phone, [$doctorName, $date, $time]);
}
public static function paymentConfirmation($phone, $amount, $transactionId)
{
return new self('paymentConfirmed', $phone, [$amount, $transactionId]);
}
public static function productAvailable($phone, $productName, $price)
{
return new self('productAvailable', $phone, [$productName, $price]);
}
}
use App\Notifications\CustomSmsNotification;
$user->notify(CustomSmsNotification::appointmentReminder(
'09123456789',
'Dr. Smith',
'1403/10/15',
'14:30'
));
namespace App\Services;
use MahdiHejazi\LaravelGhasedakSms\Notifications\SendSmsNotification;
use Illuminate\Support\Facades\Notification;
class BusinessSmsService
{
public function sendAppointmentReminder($phone, $doctorName, $date, $time)
{
return Notification::route('sms', $phone)
->notify(new SendSmsNotification('appointmentReminder', $phone, [
$doctorName, $date, $time
]));
}
public function sendLowStockAlert($phone, $productName, $currentStock)
{
return Notification::route('sms', $phone)
->notify(new SendSmsNotification('lowStock', $phone, [
$productName, $currentStock
]));
}
}
use App\Services\BusinessSmsService;
$smsService = new BusinessSmsService();
$smsService->sendAppointmentReminder('09123456789', 'Dr. Smith', '1403/10/15', '14:30');
use MahdiHejazi\LaravelGhasedakSms\Notifications\SendSmsNotification;
public function boot()
{
SendSmsNotification::macro('courseEnrollment', function ($phone, $courseName, $startDate) {
return new SendSmsNotification('courseEnrollment', $phone, [$courseName, $startDate]);
});
}
// Extend the notification class
class EcommerceSmsNotification extends SendSmsNotification
{
public static function orderShipped($phone, $orderNumber, $trackingCode)
{
return new self('orderShipped', $phone, [$orderNumber, $trackingCode]);
}
public static function priceDropAlert($phone, $productName, $newPrice)
{
return new self('priceDropAlert', $phone, [$productName, $newPrice]);
}
}
// Usage
$user->notify(EcommerceSmsNotification::orderShipped('09123456789', 'ORD-123', 'TR-456'));
class MedicalSmsNotification extends SendSmsNotification
{
public static function appointmentConfirmed($phone, $doctorName, $date, $time)
{
return new self('appointmentConfirmed', $phone, [$doctorName, $date, $time]);
}
}
use MahdiHejazi\LaravelGhasedakSms\Notifications\SimpleSmsNotification;
class BulkSmsService
{
public function sendToMultipleUsers($phoneNumbers, $message)
{
foreach ($phoneNumbers as $phone) {
Notification::route('sms', $phone)
->notify(new SimpleSmsNotification($phone, $message));
}
}
}