kevupton / twilavel
PHP Twilio for Laravel and Lumen
Installs: 1 063
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:extension
Requires
- php: >=5.3
- kevupton/laravel-package-service-provider: ^0.0.5
- twilio/sdk: ^5.14
Requires (Dev)
- laravel/laravel: ^5.5
- laravel/lumen: ^5.5
README
Implementation of Laravel / Lumen Twilio
composer require kevupton/twilavel
1. Install Service Provider
<?php // add directly from the app $app->register(\Kevupton\Twilavel\Providers\TwilavelServiceProvider::class);
OR
All service providers are registered in the config/app.php
configuration file.
<?php 'providers' => [ // Other Service Providers \Kevupton\Twilavel\Providers\TwilavelServiceProvider::class, ],
2. Configure
.env
configuration
TWILIO_LOG_OVERRIDE=false
TWILIO_TOKEN=your_token
TWILIO_SID=your_sid
TWILIO_FROM=SwagApp
Execute php artisan vendor:publish
for the complete config file.
Config: twilio.php
<?php return array( // set to true to prevent the 'log_override' => env('TWILIO_LOG_OVERRIDE', false), // Your Account SID and Auth Token from twilio.com/console 'sid' => env('TWILIO_SID'), 'token' => env('TWILIO_TOKEN'), // the default from which messages will be sent from 'from' => env('TWILIO_FROM', 'Twilavel'), );
3. Usage
Using the Facade
<?php \Twilio::message(new \Kevupton\Twilavel\Messages\BasicMessage('+61 123 456 789', 'Custom Body', 'From'));
Using the helper functions
<?php send_basic_message('+61 123 456 789', 'Custom Body', 'From');
Custom Message Example:
<?php namespace App\Twilio\Messages; use \Kevupton\Twilavel\Messages\Message; use App\Models\User; class VerifyPhone extends Message { const FROM = '+61123456789'; /** @var string custom verification code */ private $code; public function __construct(User $user, $mobile = null) { // use mobile other use user mobile $number = $mobile?: $user->mobile; parent::__construct($number, self::FROM); // get a random code $this->code = $user->generateMobileVerificationCode($number); } public function getBody() { return 'Your verification code: ' . $this->code; } }
Using Custom Message:
<?php send_message(new VerifyPhone($user, '+61123456789'));
5. Logging
You can choose to override sending API requests for development environment and just view them in the Log.
Simply just set TWILIO_LOG_OVERRIDE=true
in your .env
.
Contributing
Feel free to make a pull request at any time. Any help is appreciated (Y)