PHPackages                             jlorente/laravel-esendex - 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. jlorente/laravel-esendex

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

jlorente/laravel-esendex
========================

Laravel 5.6 integration for the Esendex SDK.

2.0.0(5y ago)223.9k↓48.8%1BSD-3-ClausePHPPHP &gt;=7.3

Since Nov 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jlorente/laravel-esendex)[ Packagist](https://packagist.org/packages/jlorente/laravel-esendex)[ RSS](/packages/jlorente-laravel-esendex/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (2)Versions (9)Used By (0)

Esendex SDK integration for Laravel
===================================

[](#esendex-sdk-integration-for-laravel)

Laravel integration for the Esendex SDK including a notification channel.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

With Composer installed, you can then install the extension using the following commands:

```
$ php composer.phar require jlorente/laravel-esendex
```

or add

```
...
    "require": {
        "jlorente/laravel-esendex": "*"
    }
```

to the `require` section of your `composer.json` file.

Configuration
-------------

[](#configuration)

1. Register the ServiceProvider in your config/app.php service provider list.

config/app.php

```
return [
    //other stuff
    'providers' => [
        //other stuff
        \Jlorente\Laravel\Esendex\EsendexServiceProvider::class,
    ];
];
```

2. If you want, you can add the following facade to the $aliases section.

config/app.php

```
return [
    //other stuff
    'aliases' => [
        //other stuff
        'Esendex' => \Jlorente\Laravel\Esendex\Facades\Esendex::class,
    ];
];
```

3. Set the reference, username and password of your esendex account in the config/services.php file inside an array with 'esendex' as key.

config/services.php

```
return [
    //other stuff
    'esendex' => [
        'reference' => '', // your account reference
        'username' => '', // your account username
        'password' => '', // your account password
        'default_from' => 'Laravel', // optional name of the sender
        'dry_run' => false, // only for the notification channel, if true, no sms's will be sent
        'throw_exception_on_error' => true // This will throw up the Esendex sdk exception if an exception is thrown by the dispatchService on the EsendexSmsChannel
    ];
];
```

Usage
-----

[](#usage)

You can use the facade alias Esendex to execute services of the esendex sdk. The authentication params will be automaticaly injected.

```
Esendex::dispatchService()->send(new DispatchMessage(
    $sender
    , $phone
    , $text
    , Message::SmsType
));
```

You can see a full list of the esendex sdk services in [this page](https://developers.esendex.com/SDKs/PHP-SDK).

Notification Channel
--------------------

[](#notification-channel)

A notification channel is included in this package and allows you to integrate the Esendex service with the Laravel notifications.

### Formatting Notifications

[](#formatting-notifications)

If a notification supports being sent as an SMS through Esendex, you should define a toEsendex method on the notification class. This method will receive a $notifiable entity and should return a Jlorente\\Laravel\\Esendex\\Notifications\\Messages\\EsendexMessage instance or a string containing the message to send:

```
/**
 * Get the Esendex / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Jlorente\Laravel\Esendex\Notifications\Messages\EsendexMessage|string
 */
public function toEsendex($notifiable)
{
    return (new EsendexMessage)
                ->content('Your SMS message content');
}
```

Once done, you must add the notification channel in the array of the via() method of the notification:

```
/**
 * Get the notification channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [EsendexSmsChannel::class];
}
```

### Customizing The Name of the Sender

[](#customizing-the-name-of-the-sender)

If you would like to send some notifications with a sender name that is different from the one specified in your config/services.php file, you may use the from method on a EsendexMessage instance:

```
/**
 * Get the Esendex / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Jlorente\Laravel\Esendex\Notifications\Messages\EsendexMessage|string
 */
public function toEsendex($notifiable)
{
    return (new EsendexMessage)
                ->content('Your SMS message content')
                ->from('Popilio');
}
```

### Routing the Notifications

[](#routing-the-notifications)

When sending notifications via the esendex channel, the notification system will automatically look for a phone\_number attribute on the notifiable entity. If you would like to customize the phone number the notification is delivered to, define a routeNotificationForEsendex method on the entity:

```
