1. Go to this page and download the library: Download farsi/laravel-smsir 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/ */
farsi / laravel-smsir example snippets
use Farsi\Smsir\Facades\Smsir;
// One message to one recipient
Smsir::send('09120000000', 'سلام!');
// The same message to many
Smsir::bulk('تخفیف ویژه امروز', ['09120000000', '09120000001']);
// A different message to each recipient, in one request
Smsir::likeTolike(['سلام علی', 'سلام مریم'], ['09120000000', '09120000001']);
// A template (verification) message — the OTP shape
Smsir::verify('09120000000', templateId: 100, ['CODE' => '1234']);
// Scheduled
Smsir::bulk('یادآوری', $mobiles, sendAt: now()->addHour());
Smsir::cancelScheduled($packId);
use Farsi\Smsir\Notifications\SmsirMessage;
use Illuminate\Notifications\Notification;
class SendOtp extends Notification
{
public function __construct(protected string $code) {}
public function via($notifiable): array
{
return ['smsir'];
}
public function toSmsir($notifiable): SmsirMessage
{
return SmsirMessage::verify('otp')->with(['CODE' => $this->code]);
}
}
$user->notify(new SendOtp($code));
return SmsirMessage::text('سفارش شما ارسال شد.');
use Farsi\Smsir\Events\{SmsSending, SmsSent, SmsFailed};
Event::listen(SmsSent::class, function (SmsSent $event) {
logger()->info("Sent {$event->packId} for {$event->cost} credits");
});
Event::listen(SmsSending::class, function (SmsSending $event) {
if (! app()->isProduction()) {
$event->payload['mobiles'] = ['09120000000'];
}
});
use Farsi\Smsir\Exceptions\{SmsirException, InvalidApiKeyException, ConnectionFailedException};
try {
Smsir::send('09120000000', 'سلام');
} catch (InvalidApiKeyException $e) {
// envelope status 10
} catch (ConnectionFailedException $e) {
// no answer at all — the message may still have been sent
} catch (SmsirException $e) {
$e->statusCode; // upstream status
$e->getMessage(); // upstream Persian message, verbatim
}