PHP code example of superloop-ltd / laravel-sms-clicksend
1. Go to this page and download the library: Download superloop-ltd/laravel-sms-clicksend 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/ */
superloop-ltd / laravel-sms-clicksend example snippets
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use NotificationChannels\ClickSend\ClickSendMessage;
use NotificationChannels\ClickSend\ClickSendChannel;
class ClickSendTest extends Notification
{
public $token;
/**
* Create a notification instance.
*
* @param string $token
*/
public function __construct($token)
{
$this->token = $token;
}
public function via($notifiable)
{
return [ClickSendChannel::class];
}
public function toClickSend($notifiable)
{
// statically create message object:
$message = ClickSendMessage::create("SMS test to user #{$notifiable->id} with token {$this->token} by ClickSend");
// OR instantiate:
$message = new ClickSendMessage("SMS test to user #{$notifiable->id} with token {$this->token} by ClickSend");
// available methods:
$message->content("SMS test to user #{$notifiable->id} with token {$this->token} by ClickSend");
$message->from('+6112345678');
$message->custom('123e4567-e89b-12d3-a456-426655440000'); // this can be useful for tracking message responses
return $message;
}
}
...
public function routeNotificationForClickSend()
{
return $this->phone;
}
...
$user = User::find(1);
try {
$user->notify(new ClickSendTest('ABC123'));
}
catch (\Exception $e) {
// do something when error
return $e->getMessage();
}
namespace App\Listeners;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use NotificationChannels\ClickSend\ClickSendChannel;
class NotificationFailedListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Notification failed event handler
*
* @param NotificationFailed $event
* @return void
*/
public function handle(NotificationFailed $event)
{
// Handle fail event for ClickSend
//
if($event->channel == ClickSendChannel::class) {
echo 'failed'; dump($event);
$logData = [
'notifiable' => $event->notifiable->id,
'notification' => get_class($event->notification),
'channel' => $event->channel,
'data' => $event->data
];
Log::error('Notification Failed', $logData);
}
// ... handle other channels ...
}
}
$client = app(ClickSendApi::class)->getClient();
// then get for eaxample yor ClickSend account details:
$account = $client->getAccount()->getAccount();
// or list of countries:
$countries = $client->getCountries()->getCountries();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.