Laravel SMS allows you to send SMS from your Laravel application using multiple sms providers, allow to add custom sms provider

Overview

Laravel SMS

Laravel SMS allows you to send SMS from your Laravel application using multiple sms providers, allow to add custom sms provider

Requirements

  • php ^7.3|^8.0
  • guzzlehttp/guzzle ^7.0.1

Installation

To get the latest version of laravel-sms on your project, require it from "composer":

$ composer require prgayman/laravel-sms

Or you can add it directly in your composer.json file:

{
  "require": {
    "prgayman/laravel-sms": "1.0.0"
  }
}

Laravel

Register the provider directly in your app configuration file config/app.php config/app.php:

Laravel >= 5.5 provides package auto-discovery, thanks to rasmuscnielsen and luiztessadri who help to implement this feature in Zatca, the registration of the provider and the facades should not be necessary anymore.

'providers' => [
    Prgayman\Sms\SmsServiceProvider::class,
]

Add the facade aliases in the same file:

'aliases' => [
  'Sms' => Prgayman\Sms\Facades\Sms::class,
]

Lumen

Register the provider in your bootstrap app file boostrap/app.php

Add the following line in the "Register Service Providers" section at the bottom of the file.

$app->register(Prgayman\Sms\SmsServiceProvider::class);

For facades, add the following lines in the section "Create The Application" .

class_alias(\Prgayman\Sms\Facades\Sms::class, 'Sms');

Run Migrations

Publish the migrations with this artisan command:

$ php artisan vendor:publish --tag=laravel-sms-migrations

Configuration

You can publish the config file with this artisan command:

$ php artisan vendor:publish --tag=laravel-sms-config

Available SMS Providers

Provider URL Tested Config
JawalSms https://www.jawalsms.net/ Yes Click
Taqnyat https://www.taqnyat.sa/ Yes Click
Nexmo https://www.nexmo.com/ Yes Click
Twilio https://www.twilio.com/ Yes Click

Available SMS Drivers local development

Provider Config
array -
log Click

Events

  • \Prgayman\Sms\Events\MessageSending::class
  • \Prgayman\Sms\Events\MessageSent::class
  • \Prgayman\Sms\Events\MessageFailed::class

Usage

Set default driver

Using .env

SMS_DRIVER=log

Using facades

/**
 * Set the default sms driver name.
 * 
 * @param string $driver
*/
Prgayman\Sms\Facades\Sms::setDefaultDriver("array");

Enable sms history using database

  • Enable the key SMS_HISTORY_ENABLED in .env file

    SMS_HISTORY_ENABLED=true
    
  • Make sure publish the migrations with this artisan command:

    $ php artisan vendor:publish --tag=laravel-sms-migrations
    
  • Run migrate with this artisan command:

    $ php artisan migrate
    

Send Message

You can simply send a message like this:

# Send message using facade
use Prgayman\Sms\Facades\Sms;

$to = "+962790000000";
$from = "SenderName";
$message = "Test Send Message";

/**
 * Send using default driver sms
 * 
 * @return \Prgayman\Sms\SmsDriverResponse
 */
$response = Sms::to($to)->from($from)->message($message)->send(); 

# Get Message
$response->getMessage();

# Get Request
$response->getRequest();

# Get driver response
$response->getResponse();

# Check is successfuly send sms message
$response->successful();

# Check is failed send sms message
$response->failed();

Send using select driver sms

Sms::driver("array")->to($to)->from($from)->message($message)->send();

Send using helper function with default driver

sms()->to($to)->from($from)->message($message)->send();

Send using helper function and select driver

sms("array")->to($to)->from($from)->message($message)->send();

Create custom driver

  • Create class extends from \Prgayman\Sms\Drivers\Driver and handler send function

    use Prgayman\Sms\Drivers\Driver;
    
    class CustomDriver extends Driver {
    
        # You not need to run events or store history 
        # package automatically run all events and store history
        public function send() : \Prgayman\Sms\SmsDriverResponse
        {
            $to = $this->getTo();
            $from = $this->getFrom();
            $message = $this->getMessage();
    
            # Handler send message
        }
    
    }
  • Add driver confg in config/sms.php

      "drivers"=>[
        .......
    
        # Use custom driver
        'your-driver-name'=>[
          'handler'=> \App\SmsDrivers\CustomDriver::class
        ],
    
        # Use supported drivers but different name
        # Copy driver object and change name
        "new-log-driver" => [
              "driver" => "log",
              'channel' => env('SMS_LOG_CHANNEL'),
        ],
      ]
  • Send message with custom driver

    # Use driver 
    Sms::driver("your-driver-name")
        ->to($to)
        ->from($from)
        ->message($message)
        ->send();
    
    # Or set custom driver in default driver or set 
    # SMS_DRIVER=your-driver-name in dotenv file
    Sms::setDefaultDriver("your-driver-name");
    
    Sms::to($to)
      ->from($from)
      ->message($message)
      ->send();

Channel Usage

First you have to create your notification using php artisan make:notification command. then Prgayman\Sms\Channels\SmsChannel::class can be used as channel like the below:

use Illuminate\Notifications\Notification;
use Prgayman\Sms\SmsNotification;

class SendSmsNotification extends Notification
{

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['sms']; # add this channel
    }

    /**
     * @param mixed $notifiable
     * @return \Prgayman\Sms\SmsNotification
     */
    public function toSms($notifiable)
    {
        # Send message with default driver
        return (new SmsNotification)
          ->to("+962790000000")
          ->from("SenderName")
          ->message("Test New Message");

        # Send message with select driver
        return (new SmsNotification)
          ->driver('array')
          ->to("+962790000000")
          ->from("SenderName")
          ->message("Test New Message");
    }
}

SMS History

use Prgayman\Sms\Facades\SmsHistory;

# Get all
$histories = SmsHistory::get();

# Use Filters all filter is optional
$histories = SmsHistory::recipients("+962790000000")
->senders(["SendName"])
->statuses([
  Prgayman\Sms\Models\SmsHistory::SUCCESSED,
  Prgayman\Sms\Models\SmsHistory::FAILED,
])
->drivers(["log","array"])
->driverNames(["custom_name"])
->get();

# Or can use helper function
$histories = smsHistory()
->recipients("+962790000000")
->senders(["SendName"])
->statuses([
  Prgayman\Sms\Models\SmsHistory::SUCCESSED,
  Prgayman\Sms\Models\SmsHistory::FAILED,
])
->drivers(["log","array"])
->driverNames(["custom_name"])
->get();

Testing

composer test

Licence

This library is open-sourced software licensed under the MIT license.

You might also like...
Set multiple alerts from your backend, render them in the frontend with any HTML

Alerts Set multiple alerts from your backend, render them in the frontend with any HTML. alert('This is awesome! 😍', 'success') div class="alert ale

Send Firebase push notifications with Laravel php framework.

FCM Notification Channel for Laravel Send Firebase push notifications with Laravel php framework. Installation You can install this package via compos

This package makes it easy to send web push notifications with Laravel.

Web push notifications channel for Laravel This package makes it easy to send web push notifications with Laravel. Installation You can install the pa

A PHP Library to easily send push notifications with the Pushwoosh REST Web Services.

php-pushwoosh A PHP Library to easily send push notifications with the Pushwoosh REST Web Services. First sample, creating a Pushwoosh message // Crea

Notifications in PHP (notify-send, growl, etc) like that.

#Nod Notifications in PHP (notify-send, growl, etc) like that. ##Examples Letting Nod figure out the best Adapter to use (not recommend ATM, only work

Send push notifications to apple devices (iPhone, iPad, iPod).

Apple Apn Push Send push notifications to apple devices (iPhone, iPad, iPod). Support authenticators: Certificate Json Web Token Supported protocols:

WebPush can be used to send notifications to endpoints which server delivers Web Push

WebPush can be used to send notifications to endpoints which server delivers Web Push notifications as described in the Web Push protocol. As it is standardized, you don't have to worry about what server type it relies on.

It's Pimcore Bundle to send notifications to Google Chat, Slack or Email from admin panel inside Pimcore
It's Pimcore Bundle to send notifications to Google Chat, Slack or Email from admin panel inside Pimcore

Send notifications to Discord, Google Chat, Slack and more from Pimcore It's Pimcore Bundle to send notifications to Discord, Google Chat, Slack, Tele

Multiple channels of laravel exception notification(DingTalk、FeiShu、ServerChan、WeWork、XiZhi). - 多种通道的 laravel 异常通知(钉钉群机器人、飞书群机器人、Server 酱、企业微信群机器人、息知)。
Multiple channels of laravel exception notification(DingTalk、FeiShu、ServerChan、WeWork、XiZhi). - 多种通道的 laravel 异常通知(钉钉群机器人、飞书群机器人、Server 酱、企业微信群机器人、息知)。

laravel-exception-notify 简体中文 | ENGLISH Multiple channels of laravel exception notification(DingTalk、FeiShu、ServerChan、WeWork、XiZhi). - 多种通道的 laravel

Releases(1.4.4)
Owner
Ayman Alaiwah
CS, Full Stack Developer ,Flutter ,React Native, Web
Ayman Alaiwah
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.

Introduction Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel. Firebase Cloud Messagin

Kutia Software Company 264 Jan 7, 2023
Send SMS with easy using BEEM

beem-sms-api Send SMS with easy using BEEM Installation You must be using composer to be able to use this library. If composer 1.x is installed, make

Hosanna Higher Technologies 4 Dec 24, 2021
SMS service provider for Laravel

laravel-sms SMS service provider for Laravel and Lumen. Uses SMS Client to enable sending SMS messages using the following drivers: nexmo clockwork te

Matthew Daly 34 Nov 29, 2022
This package allows you to send notifications to Microsoft Teams.

Teams connector This package allows you to send notifications to Microsoft Teams. Installation You can install the package using the Composer package

skrepr 20 Oct 4, 2022
@Authy notification channel for @Laravel, with the ability to send in-app, sms, and call verification tokens.

Authy Notification Channel for Laravel Authy notification channel for Laravel, with the ability to send in-app, sms, and call verification tokens. Tab

Laravel Notification Channels 57 Dec 19, 2022
laravel send sms. kavenegar, ghasedak

Requirements laravel >= 7 Installation composer require ehsanmoradi/laravel-sms Publish the configuration file (this will create a laravel-sms.php

ehsan moradi 3 Feb 6, 2022
:computer: Send notifications to your desktop directly from your PHP script

About JoliNotif JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS. Requires PHP >= 7.2 (

JoliCode 1.2k Dec 29, 2022
Service that helps you to send notifications for a series of failed exceptions.

Laravel Failure Notifier This package helps you to track your exceptions and do what you want to do with them such as sending an SMS or and Email. You

Kamyar Gerami 7 Nov 26, 2022
This package makes it easy to send notifications using RocketChat with Laravel 9.0+.

laravel-rocket-chat-notifications Introduction This package makes it easy to send notifications using RocketChat with Laravel 9.0+. Contents Installat

Team Nifty GmbH 25 Dec 1, 2022
ApnsPHP: Apple Push Notification & Feedback Provider

ApnsPHP: Apple Push Notification & Feedback Provider A full set of open source PHP classes to interact with the Apple Push Notification service for th

Immobiliare Labs 1.4k Nov 16, 2022