PHPackages                             hooman-mirghasemi/laravel-iran-sms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. hooman-mirghasemi/laravel-iran-sms

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hooman-mirghasemi/laravel-iran-sms
==================================

Laravel Sms

1.4.2(5mo ago)241.8k↓33.3%2MITPHPPHP ^8.0.2CI passing

Since Sep 1Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/hooman-mirghasemi/Laravel-iran-sms)[ Packagist](https://packagist.org/packages/hooman-mirghasemi/laravel-iran-sms)[ Docs](https://github.com/hooman-mirghasemi/laravel-iran-sms)[ RSS](/packages/hooman-mirghasemi-laravel-iran-sms/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (13)Used By (0)

[![](src/Resources/images/sms.jpg?raw=true)](src/Resources/images/sms.jpg?raw=true)

Laravel Iran Sms
================

[](#laravel-iran-sms)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Version on Packagist](https://camo.githubusercontent.com/27838879cf074737e253bd21b51f5ad54bd06b886a5a216ca03c6ad8a984f43c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686f6f6d616e2d6d697267686173656d692f6c61726176656c2d6972616e2d736d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hooman-mirghasemi/laravel-iran-sms)[![Total Downloads on Packagist](https://camo.githubusercontent.com/de7e0336f390c997ab4bc0dc1253f354ba7aa1f915f0e20ce6b0e778e6b0b20b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f6f6d616e2d6d697267686173656d692f6c61726176656c2d6972616e2d736d732e7376673f636f6c6f723d253233463138267374796c653d666c61742d737175617265)](https://packagist.org/packages/hooman-mirghasemi/laravel-iran-sms)[![StyleCI](https://camo.githubusercontent.com/e6f40e5e1d47781f7ae8af475e879a06038f7724ec9e37c3cd4de00bd4cdd264/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3638343231303232352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/684210225)[![Maintainability](https://camo.githubusercontent.com/7080479c35d6a2915249b42e4b7cfa5d474ea75f599e168028fa489cb0fbf23f/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f39653234313565306366636665323132306139652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/hooman-mirghasemi/Laravel-iran-sms/maintainability)[![Quality Score](https://camo.githubusercontent.com/7bb01f176e4dcd93a63311fa27e48224ffd009f61d226a99318a2662398813f1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f686f6f6d616e2d6d697267686173656d692f6c61726176656c2d6972616e2d736d732e7376673f6c6162656c3d436f64652532305175616c697479267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hooman-mirghasemi/laravel-iran-sms)

This is a Laravel Package for Sms Senders Integration. This package supports `Laravel 8+`, all tests passed for laravel 8, 9, 10, 11 and 12!

> Benefits of this package:
>
> - Multiple drivers
> - Support create custom drivers
> - Have Fake build in driver, it can send success or failure sms/voice call message. (Can use in development and testing modes)
> - Store sms reports in database
> - Have a tools in only development mode in  (Your frontend developer can use it for access latest sms send with fake driver for example needs to otp codes, when he/she is developing some parts like forgot password)

- [English documents](README.md)
- [داکیومنت فارسی](README_FA.md)

List of contents
================

[](#list-of-contents)

- [Laravel Iran Sms](#laravel-iran-sms)
- [List of contents](#list-of-contents)
- [List of available drivers](#list-of-available-drivers)
    - [Install](#install)
    - [.env file](#env-file)
    - [How to use](#how-to-use)
        - [Working with Facades](#working-with-Facades)
        - [Working with Channels (use laravel notification classes)](#working-with-channels-(use-laravel-notification-classes))
        - [Create custom drivers:](#create-custom-drivers)
        - [Events](#events)
    - [Contributing](#contributing)
    - [Credits](#credits)
    - [License](#license)

List of available drivers
=========================

[](#list-of-available-drivers)

- [fake sms sender](#fake-sms) : (Both: Voice call/Sms)
- [Avanak](https://www.avanak.ir/) : (Voice call driver)
- [Ghasedak](https://ghasedak.me/) : (Sms)
- [Kavenegar](https://kavenegar.com/) : (Sms)
- [Magfa](https://magfa.com/) : (Sms)
- [Sms Online](https://smsonline.ir/) : (Sms)

Note: for using each of them check config file and use the needed env in your env file like username/password or api key depend on witch driver you use.

Note: to use magfa/sms online/avanak you should install php ext-soap.

**Important:** Some drivers require additional packages. Install the driver package you need:

```
# For Kavenegar driver
composer require kavenegar/laravel
```

.env file for each driver:
--------------------------

[](#env-file-for-each-driver)

### fake sms sender

[](#fake-sms-sender)

// Use in your local .env file

SMS\_DRIVER=fake

// It's optional if you want you can set a number

FAKE\_SENDER\_NUMBER=101010

### Ghasedak

[](#ghasedak)

// Use in your production .env file if you want to use Ghasedak as default sms driver

SMS\_DRIVER=ghasedak

// Your Ghasedak account api key

GHASEDAK\_API\_KEY=your\_api\_key

// Your Ghasedak sender number (line number)

GHASEDAK\_SENDER\_NUMBER=3000xxxxx

### Kavenegar

[](#kavenegar)

// Use in your production .env file if you want to use Kavenegar as default sms driver

SMS\_DRIVER=kavenegar

// Your kavenegar account api key

KAVENEGAR\_API\_KEY=fsdf452fd

### Magfa

[](#magfa)

// Use in your production .env file if you want to use Magfa as default sms driver

SMS\_DRIVER=magfa

SMS\_MAGFA\_USERNAME=your magfa user name

SMS\_MAGFA\_PASSWORD=your magfa password

SMS\_MAGFA\_DOMAIN=your magfa domain

SMS\_MAGFA\_SENDER\_NUMBER=your number in magfa you want to send sms with it

### Sms Online

[](#sms-online)

// Use in your production .env file if you want to use Sms Online as default sms driver

SMS\_DRIVER=smsonline

SMS\_ONLINE\_USERNAME=your smsonline user name

SMS\_ONLINE\_PASSWORD=your smsonline password

SMS\_ONLINE\_SENDER\_NUMBER=your number in smsonline you want to send sms with it

### Avanak (voice caller)

[](#avanak-voice-caller)

// Use in your production .env file if you want to use Sms Online as default sms driver

VOICE\_CALL\_DRIVER=avanak

VOICE\_AVANAK\_USERNAME=your avanak user name

VOICE\_AVANAK\_PASSWORD=your avanak password

> you can create your own custom drivers if it does not exist in the list, read the `Create custom drivers` section.

Install
-------

[](#install)

Via Composer

```
$ composer require hooman-mirghasemi/laravel-iran-sms
```

Publish Vendor Files
--------------------

[](#publish-vendor-files)

It is optional and only if you need you can publish vendor files by these commands:

- **publish configuration files:**

```
php artisan vendor:publish --tag=iran-sms-config
```

- **publish views for customization:**

```
php artisan vendor:publish --tag=iran-sms-views
```

- **publish migration:**

```
php artisan vendor:publish --tag=iran-sms-migrations
```

.env file
---------

[](#env-file)

You can use `SMS_DRIVER` env for set default sms driver. (in local don't change it, by default it set fake driver)

And also can use `VOICE_CALL_DRIVER` env. it is like SMS\_DRIVER, but for voice call.

How to use
----------

[](#how-to-use)

There are two option of using this package:

1- use Facades

2- use Channels

#### Working with Facades

[](#working-with-facades)

You can use `Sms` or `VoiceCall` facades in anywhere of your code like this:

```
// At the top of the file.
use HoomanMirghasemi\Sms\Facades\Sms;
...

Sms::to('+989121234567')->message('your sms text')->send();

//Also you can set driver in run time:
Sms::driver('magfa')->to('+989121234567')->message('your sms text')->send();
```

available methods:

- `to`: set the mobile number should get sms.
- `message`: the text message can be a simple string or object of a class implement HoomanMirghasemi\\Sms\\Contracts\\Message interface
- `send`: send the message.

#### Working with Channels (use laravel notification classes)

[](#working-with-channels-use-laravel-notification-classes)

Make a laravel notification class, set via `SmsChannel` like this code:

```
// At the top of the file.
use HoomanMirghasemi\Sms\Channels\SmsChannel;
use HoomanMirghasemi\Sms\Contracts\Message\Message;
...

public function __construct(public SomeModel $someModel)
{
    $this->via = SmsChannel::class;
}

public function toSms(User $notifiable)
{
    $smsMessage = 'make your sms text ';
    // only if using kavehnegar set the pattern name
    $pattern = 'kavenagarMyPatternName';

    $message = new Message($smsMessage);
    $message->useTemplateIfSupports(
        $pattern,
        [
            'token1' => 'test',
            'token10' => $notifiable->name,
            'token20' => $this->family
        ]
    );

    return Sms::to($notifiable->mobile)
        ->message($message);
}
```

#### Change condition of showing sms list page

[](#change-condition-of-showing-sms-list-page)

By default when your laravel application is in production mode this page will response 404. You can now control this via `.env` file:

```
# Set to true to hide the SMS list page (default: true in production)
DONT_SHOW_SMS_LIST_PAGE=true

```

Or if you want more control, publish the config file and customize the condition:

```
// default config is:
'dont_show_sms_list_page_condition' => env(
    'DONT_SHOW_SMS_LIST_PAGE',
    env('APP_ENV', 'production') == 'production'
),

// you can check any thing like domain:
'dont_show_sms_list_page_condition' => env('APP_ENV') == 'production' || config('app.url') == 'https://yourproductiondomain.com',
```

now if you forgot to set app.env to production or temporary change it, it will be safe and return 404.

#### Create custom drivers:

[](#create-custom-drivers)

Option A:

We welcome your participation, Create your driver and send a pull request.

Option A: This package is using strategy design pattern and laravel `Manager` class. so you can easily make your driver like this:

```
