PHP code example of boyo / laravel-twilio

1. Go to this page and download the library: Download boyo/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/ */

    

boyo / laravel-twilio example snippets


'twilio' => [
	'token' => env('TWILIO_TOKEN',''),
	'sid' => env('TWILIO_SID',''),
	'send' => env('TWILIO_SEND',false),
	'from' => env('TWILIO_FROM',''),
	'log' => env('TWILIO_LOG',true),
	'log_channel' => env('TWILIO_LOG_CHANNEL','stack'),
	'prefix' => '',
	'allow_multiple' => false,
],

use Boyo\Twilio\TwilioMessage;
use Boyo\Twilio\TwilioSender;

class MyClass
{
	public function myFunction()
	{
		$message = (new TwilioMessage())->to('359888888888')->sms('SMS text');
		
		$client = new TwilioSender();
		$client->send($message);	
	}
}

use Boyo\Twilio\TwilioMessage;

class MyMessage extends TwilioMessage 
{
	public function __construct($data)
    {
        $this->id = $data->id; // your unique message id, add other parameters if needed
    }
    
	public function build() {
		// set your sms text 
		$this->sms('SMS text');
		
		return $this;
	}	
}

use Boyo\Twilio\TwilioChannel;

via($notifiable) 
{
	
	// ...
	
	$via[] = TwilioChannel::class;
	
	return $via 
	
}

public function toSms($notifiable)
{
	return (new MyMessage($unique_id))->to($notifiable->phone);
}