PHPackages                             homedoctor-es/laravel-instasent - 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. homedoctor-es/laravel-instasent

ActiveLibrary

homedoctor-es/laravel-instasent
===============================

Laravel 5.8 integration for the Instasent SDK.

1.0.1(4y ago)08BSD-3-ClausePHPPHP &gt;=7.1.3

Since Feb 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/homedoctor-es/laravel-instasent)[ Packagist](https://packagist.org/packages/homedoctor-es/laravel-instasent)[ RSS](/packages/homedoctor-es-laravel-instasent/feed)WikiDiscussions master Synced 2d ago

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

Instasent SDK integration for Laravel
=====================================

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

Laravel integration for the Instasent 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 homedoctor-es/laravel-instasent
```

or add

```
...
    "require": {
        "homedoctor-es/laravel-instasent": "*"
    }
```

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
        \HomedoctorEs\Laravel\Instasent\InstasentServiceProvider::class,
    ];
];
```

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

config/app.php

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

3. Publish the package configuration file.

```
$ php artisan vendor:publish --provider='HomedoctorEs\Laravel\Instasent\InstasentServiceProvider'
```

4. Set the api\_token in the config/instasent.php file or use the predefined env variables.

config/instasent.php

```
return [
    'api_token' => '', // your account api token
    '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 Instasent sdk exception if an exception is thrown by the dispatchService on the InstasentSmsChannel
];
```

or .env

```
//other configurations
INSTASENT_API_TOKEN=

```

Usage
-----

[](#usage)

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

```
Instasent::clientSms()->sendSms(
    $sender
    , $phone
    , $text
);
```

You can see a full list of the instasent sdk services in [this page](https://docs.instasent.com/1.0/sdks/php-sdk).

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

[](#notification-channel)

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

### Formatting Notifications

[](#formatting-notifications)

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

```
/**
 * Get the Instasent / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \HomedoctorEs\Laravel\Instasent\Notifications\Messages\InstasentMessage|string
 */
public function toInstasent($notifiable)
{
    return (new InstasentMessage)
                ->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 [InstasentSmsChannel::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 InstasentMessage instance:

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

### Routing the Notifications

[](#routing-the-notifications)

When sending notifications via the instasent 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 routeNotificationForInstasent method on the entity:

```
