twilioman/twilio

Twilio API for Laravel

Downloads

126

Stars

0

Version

0.1

laravel-twilio

Laravel Twillio API Integration

Latest Unstable Version License

Installation

Begin by installing this package through Composer. Run this command from the Terminal:

composer require twilioman/twilio

If you're using Laravel 5.5+, this is all there is to do.

Should you still be on older versions of Laravel, the final steps for you are to add the service provider of the package and alias the package. To do this open your config/app.php file.

Integration for older versions of Laravel (5.5 -)

To wire this up in your Laravel project, you need to add the service provider. Open app.php, and add a new item to the providers array.

'TwilioMan\LaravelTwilio\Provider\ServiceProvider',

There's a Facade class available for you, if you like. In your app.php config file add the following line to the aliases array if you want to use a short class name:

'Twilio' => 'TwilioMan\LaravelTwilio\Facade\Facade',

Facade

First, include the Facade class at the top of your file:

use TwilioMan\LaravelTwilio\Twilio;

To send a message using the default entry from your twilio :

Twilio::message($user->phone, $message);

Usage

Creating a Twilio object.

$twilio = new TwilioMan\LaravelTwilio\Twilio($accountId, $token, $fromNumber);

Sending a text message:

$twilio->message('+18085551212', 'Pink Elephants and Happy Rainbows');

Access the configured Twilio\Rest\Client object:

$sdk = $twilio->getTwilio();

You can also access this via the Facade as well:

$sdk = Twilio::getTwilio();

Pass as many optional parameters as you want

If you want to pass on extra optional parameters to the messages->sendMessage(...) method from the Twilio SDK, you can do so by adding to the message method. All arguments are passed on, and the from field is prepended from configuration.

$twilio->message($to, $message, $mediaUrls, $params);
// passes all these arguments on.
chetanhub

Author

chetanhub