PHP code example of i-rocky / laravel-twilio

1. Go to this page and download the library: Download i-rocky/laravel-twilio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

i-rocky / laravel-twilio example snippets


...   
    'twilio' => [
        'account_sid' => env('TWILIO_ACCOUNT_SID'),
        'auth_token'  => env('TWILIO_AUTH_TOKEN'),
        'caller_id'   => env('TWILIO_NUMBER'),
        'username'    => env('TWILIO_USERNAME'),
        'password'    => env('TWILIO_PASSWORD'),
        'app_sid'     => env('TWIML_APP_SID'),
    ],
...

/**
 * @property string username
 * @property string phone
 * @property string phone_number
 */
clas User extends Authenticable {
    use Notifiable;

...

    public function routeNotificationForTwilio() {
        return "+{$this->phone}";
    }
    
    public function laravelTwilioIdentity() {
        return Str::snake($this->first_name);
    }
}


use Rocky\LaravelTwilio\Foundation\TwilioMessage;
use Rocky\LaravelTwilio\Message\TwilioSMSMessage;
use Rocky\LaravelTwilio\Message\TwilioMMSMessage;
use Rocky\LaravelTwilio\Message\TwilioFaxMessage;
use Rocky\LaravelTwilio\Message\TwilioCallMessage;
use Rocky\LaravelTwilio\TwilioChannel;

class TwilioTestNotification extends Notification {

...

    public function via($notifiable) {
        return [TwilioChannel::class];
    }

...

    public function toTwilio($notifiable) {
        // SMS
        return (new TwilioSMSMessage())
            ->to('+receiver') // optional
            ->from('+sender') // optional
            ->text('Your message'); //     ->mediaUrl('publicly accessible media url'); // 

$call = $event->getCall();

$sid = $call->CallSid;
$sid = $call->callSid;
$sid = $call->call_sid;

$from = $call->From;
$from = $call->from;

$allParams = $call->all();