PHPackages                             dmitrakovich/smstraffic-for-laravel - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dmitrakovich/smstraffic-for-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dmitrakovich/smstraffic-for-laravel
===================================

SmsTraffic Client for Laravel

0.4.0(1y ago)02.4k↑350%MITPHPPHP ^8.0

Since Oct 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dmitrakovich/smstraffic-for-laravel)[ Packagist](https://packagist.org/packages/dmitrakovich/smstraffic-for-laravel)[ RSS](/packages/dmitrakovich-smstraffic-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

SmsTraffic for Laravel
======================

[](#smstraffic-for-laravel)

Details
-------

[](#details)

Inspired by [Laravel Vonage Notification Channel](https://github.com/laravel/vonage-notification-channel).

Note
----

[](#note)

This library implements limited functionality.

Documentation
-------------

[](#documentation)

Sending SMS notifications in Laravel is powered by [SMS Traffic](https://www.smstraffic.ru/). Before you can send notifications via SMS Traffic, you need to install the `dmitrakovich/smstraffic-for-laravel` and `guzzlehttp/guzzle` packages:

```
composer require dmitrakovich/smstraffic-for-laravel guzzlehttp/guzzle
```

The package includes a [configuration file](https://github.com/dmitrakovich/smstraffic-for-laravel/blob/main/config/smstraffic.php). However, you are not required to export this configuration file to your own application. You can simply use environment variables.

```
SMSTRAFFIC_SMS_FROM=
SMSTRAFFIC_LOGIN=
SMSTRAFFIC_PASSWORD=
SMSTRAFFIC_ROUTE=
```

### Formatting SMS Notifications

[](#formatting-sms-notifications)

If a notification supports being sent as an SMS, you should define a `toSmsTraffic` method on the notification class. This method will receive a `$notifiable` entity and should return an `Illuminate\Notifications\Messages\SmsTrafficMessage` instance:

```
/**
 * Get the SmsTraffic / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\SmsTrafficMessage
 */
public function toSmsTraffic($notifiable)
{
    return (new SmsTrafficMessage)
                ->content('Your SMS message content');
}
```

#### Notification route

[](#notification-route)

If you would like to send some notifications to another route that is different route specified by your `SMSTRAFFIC_ROUTE` environment variable, you may call the `route` method on a `SmsTrafficMessage` instance:

```
/**
 * Get the SmsTraffic / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\SmsTrafficMessage
 */
public function toSmsTraffic($notifiable)
{
    return (new SmsTrafficMessage)
                ->content('Your unicode message')
                ->route('whatsapp(180)-sms');
}
```

### Customizing The "From" Number

[](#customizing-the-from-number)

If you would like to send some notifications from a phone number that is different from the phone number specified by your `SMSTRAFFIC_SMS_FROM` environment variable, you may call the `from` method on a `SmsTrafficMessage` instance:

```
/**
 * Get the SmsTraffic / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\SmsTrafficMessage
 */
public function toSmsTraffic($notifiable)
{
    return (new SmsTrafficMessage)
                ->content('Your SMS message content')
                ->from('15554443333');
}
```

### Routing SMS Notifications

[](#routing-sms-notifications)

To route SmsTraffic notifications to the proper phone number, define a `routeNotificationForSmsTraffic` method on your notifiable entity:

```
