PHPackages                             jlorente/laravel-connectus - 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. [API Development](/categories/api)
4. /
5. jlorente/laravel-connectus

ActiveLibrary[API Development](/categories/api)

jlorente/laravel-connectus
==========================

Laravel integration for the Jlorente Connectus php sdk.

1.0.2(4y ago)15.0k↓50%BSD-3-ClausePHPPHP &gt;=7.1.3

Since Feb 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jlorente/laravel-connectus)[ Packagist](https://packagist.org/packages/jlorente/laravel-connectus)[ RSS](/packages/jlorente-laravel-connectus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Connectus SDK for Laravel
=========================

[](#connectus-sdk-for-laravel)

Laravel integration for the [Connectus SDK](https://github.com/jlorente/connectus-php-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-connectus
```

or add

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

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\Connectus\ConnectusServiceProvider::class,
    ];
];
```

2. Add the following facade to the $aliases section.

config/app.php

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

3. Publish the package configuration file.

```
$ php artisan vendor:publish --provider='Jlorente\Laravel\Connectus\ConnectusServiceProvider'
```

4. Set the api\_key and api\_secret in the config/connectus.php file or use the predefined env variables.

config/connectus.php

```
return [
    'api_key' => 'YOUR_API_KEY',
    'account_id' => 'YOUR_ACCOUNT_ID',
    //other configuration
];
```

or .env

```
//other configurations
CONNECTUS_API_KEY=
CONNECTUS_ACCOUNT_ID=

```

Usage
-----

[](#usage)

You can use the facade alias Connectus to execute api calls. The authentication params will be automaticaly injected.

```
Connectus::api()->checkSmsBalance();
```

Notification Channels
---------------------

[](#notification-channels)

A notification channel is included in this package and allow you to integrate the Connectus send SMS service.

You can find more info about Laravel notifications in [this page](https://laravel.com/docs/5.6/notifications).

### ConnectusSmsChannel

[](#connectussmschannel)

If you want to send an SMS through Connectus, you should define a toConnectusSms method on the notification class. This method will receive a $notifiable entity and should return a string with the message to be sent on the SMS:

```
/**
 * Get the SMS message.
 *
 * @param  mixed  $notifiable
 * @return string
 */
public function toConnectusSms($notifiable)
{
    return 'Hello, this is an SMS sent through Connectus API';
}
```

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 [ConnectusSmsChannel::class];
}
```

### Routing the Notifications

[](#routing-the-notifications)

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

```
