nikajorjika/laravel-sms-office
Laravel package integrating smsoffice.ge SMS sending. Configure API key, sender, and no-SMS code via .env/config. Send messages via SmsOffice facade or as a Laravel Notification channel, with a log driver available for testing.
Installation:
composer require nikajorjika/laravel-sms-office
Publish the config file:
php artisan vendor:publish --provider="Nikajorjika\SmsOffice\SmsOfficeServiceProvider" --tag="config"
Configure .env:
SMS_OFFICE_DRIVER=sms-office
SMS_OFFICE_KEY=your_api_key
SMS_OFFICE_FROM=YourSenderName
SMS_OFFICE_NOSMS=no_sms_code
First Use Case: Send an SMS via facade:
use Nikajorjika\SmsOffice\Facades\SmsOffice;
SmsOffice::message("Hello via SMS!")->to("995551234567")->send();
Basic SMS Send:
SmsOffice::message("Your OTP is 1234.")
->to("995551234567")
->urgent(true) // Optional: Mark as urgent
->send();
Dynamic Messages:
$phone = $user->phone_number;
$message = "Welcome, {$user->name}! Your account is active.";
SmsOffice::message($message)->to($phone)->send();
Extend Notification:
use Nikajorjika\SmsOffice\SmsOfficeChannel;
class AccountActivationNotification extends Notification
{
public function via($notifiable)
{
return [SmsOfficeChannel::class];
}
public function toSms($notifiable)
{
return "Hello {$notifiable->name}, your account is now active!";
}
}
Route SMS in Model:
class User extends Authenticatable
{
public function routeNotificationForSms()
{
return $this->phone_number; // Must return valid phone (e.g., "995551234567")
}
}
Trigger Notification:
$user->notify(new AccountActivationNotification());
$user->notify(new AccountActivationNotification())->onQueue('sms');
log driver (no API calls):
SMS_OFFICE_DRIVER=log
Logs will appear in storage/logs/laravel.log.Phone Number Format:
995551234567).Str::startsWith($phone, '995') or similar.$urgent Parameter:
"true"/"false") or null.
// ❌ Fails (PHP 8+ strict mode)
SmsOffice::message("Hi")->urgent(false)->send();
"true"/"false" strings or omit:
SmsOffice::message("Hi")->urgent("true")->send();
No-SMS Code:
SMS_OFFICE_NOSMS is set, the package auto-appends [no_sms] to messages.SMS_OFFICE_NOSMS=null in config.Config Key Mismatch:
"sender" instead of "from".log driver to debug messages without API calls.storage/logs/laravel.log for SMS Office API responses.Custom Drivers:
Extend Nikajorjika\SmsOffice\Contracts\Driver to add new providers (e.g., Twilio).
class CustomDriver implements Driver {
public function send($message, $phone, $urgent = null) { ... }
}
Register in config/smsoffice.php:
'supported_drivers' => ['sms-office', 'log', 'custom-driver'],
Message Formatting:
Override the SmsOffice facade to preprocess messages:
SmsOffice::extend(function ($app) {
$facade = new SmsOffice($app);
$facade->setFormatter(function ($message) {
return "[Custom] " . $message;
});
return $facade;
});
Webhook Validation:
For production, validate SMS Office’s API responses (e.g., check for success: true in the response).
SmsOffice facade to test notifications:
$this->mock(SmsOffice::class)->shouldReceive('send')->once();
log driver to assert message content:
$this->actingAs($user)->notify(new AccountActivationNotification());
$this->assertLogContains("Hello {$user->name}...");
How can I help you explore Laravel packages today?