parsadanashvili/laravel-smsoffice

There is no license information available for the latest version (v1.1.0) of this package.

v1.1.0 2023-08-25 16:58 UTC

This package is auto-updated.

Last update: 2024-09-25 19:34:36 UTC


README

Laravel SMSOffice Package

Latest Stable Version Total Downloads Downloads Month

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

  1. In your User model (or any model you want to send notifications to), add a routeNotificationForSms() 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
    }
}
  1. Create a notification class using the following Artisan command:
php artisan make:notification SmsNotification
  1. Inside the generated SmsNotification class, import SmsOfficeChannel and add it to the via() method. Define the toSms() 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';
    }
}
  1. 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.