parsadanashvili / laravel-smsoffice
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^7.0.1
- illuminate/support: >=5.3
This package is auto-updated.
Last update: 2025-04-25 20:37:38 UTC
README
Laravel SMSOffice Package
The Laravel SMSOffice package allows you to easily send SMS messages using the SMSOffice API. It provides a convenient way to integrate SMS functionality into your Laravel applications.
Credits
This package is a fork of the original work by lotuashvili/laravel-smsoffice. You can find the original repository here.
Installation
You can install the package using Composer:
composer require parsadanashvili/laravel-smsoffice
If you're using Laravel 5.4 or lower, you'll need to manually add the service provider to your config/app.php
file. Open the config/app.php
file and add the SmsOfficeServiceProvider
to the providers array:
// config/app.php 'providers' => [ // Other providers Parsadanashvili\LaravelSmsOffice\SmsOfficeServiceProvider::class, ],
After adding the service provider, you'll need to publish the configuration:
php artisan vendor:publish --provider="Parsadanashvili\LaravelSmsOffice\SmsOfficeServiceProvider"
Configuration
You'll need to set up the following environment variables in your .env
file:
SMSOFFICE_API_KEY=your_api_key SMSOFFICE_SENDER=your_default_sender SMSOFFICE_DRIVER=your_preferred_driver
Development
During development, you can set the SMS driver to log
by adding SMSOFFICE_DRIVER=log
to your .env
file. This will help you simulate SMS sending by logging the actions instead.
Usage
Using Notifications
- In your
User
model (or any model you want to send notifications to), add arouteNotificationForSms()
method that returns the user's phone number:
namespace App\Models; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; // Other code... public function routeNotificationForSms() { return $this->phone; // Adjust this to match your phone number field } }
- Create a notification class using the following Artisan command:
php artisan make:notification SmsNotification
- Inside the generated
SmsNotification
class, importSmsOfficeChannel
and add it to thevia()
method. Define thetoSms()
method to specify the content of your SMS:
use Illuminate\Notifications\Notification; use Parsadanashvili\LaravelSmsOffice\SmsOfficeChannel; class SMSNotification extends Notification { public function via($notifiable) { return [SmsOfficeChannel::class]; } public function toSms($notifiable) { return 'Your Notification Content Here'; } }
- You can now use this notification in your application to send SMS notifications to users:
use App\Notifications\SMSNotification; $user->notify(new SMSNotification());
Sending SMS Directly
If you want to send SMS messages without using notifications, you can do so directly:
use Parsadanashvili\LaravelSmsOffice\SmsOffice; public function sendSms(SmsOffice $smsOffice) { $smsOffice->send('599123456', 'Your Message Here'); }
Feel free to replace '599123456'
with the recipient's phone number and 'Your Message Here'
with the actual message content.
This should help clarify the installation process, configuration, and usage of the Laravel SMSOffice package.